Naoya OYAMA | 8 Feb 15:39
Picon

[RFC][PATCH] libmpcodecs/ad_spdif.c check DTS profile

Hi,

Attached patch for ad_spdif.
Improvement enumerated below was added.

1. A suitable value is set up for bitrate and channels and dtshd_rate.
By useing DTS profile.
2. The code for creating lavc is diverted from ad_ffmpeg.c.
3. By creating lavc on ad_spdif.c, detection of bitrate and
sample_rate became highly precise.

Thanks.
Index: libmpcodecs/ad_spdif.c
===================================================================
--- libmpcodecs/ad_spdif.c	(revision 34655)
+++ libmpcodecs/ad_spdif.c	(working copy)
@@ -25,6 +25,9 @@
 #include "libavformat/avformat.h"
 #include "libavcodec/avcodec.h"
 #include "libavutil/opt.h"
+#include "dec_audio.h"
+#include "help_mp.h"
+#include "libavutil/dict.h"

 static const ad_info_t info = {
     "libavformat/spdifenc audio pass-through decoder.",
@@ -39,11 +42,16 @@
 #define FILENAME_SPDIFENC "spdif"
(Continue reading)

Naoya OYAMA | 9 Feb 15:31
Picon

Re: [RFC][PATCH V2] libmpcodecs/ad_spdif.c check DTS profile

Hi,
patch updated.

+        { "mpa"   , CODEC_ID_MP3    },

This line is wrong.
The following lines are right.

+        { "mp3"   , CODEC_ID_MP3    },

Thanks.
Index: libmpcodecs/ad_spdif.c
===================================================================
--- libmpcodecs/ad_spdif.c	(revision 34665)
+++ libmpcodecs/ad_spdif.c	(working copy)
@@ -25,6 +25,9 @@
 #include "libavformat/avformat.h"
 #include "libavcodec/avcodec.h"
 #include "libavutil/opt.h"
+#include "dec_audio.h"
+#include "help_mp.h"
+#include "libavutil/dict.h"

 static const ad_info_t info = {
     "libavformat/spdifenc audio pass-through decoder.",
@@ -39,11 +42,16 @@
 #define FILENAME_SPDIFENC "spdif"
 #define OUTBUF_SIZE 65536
(Continue reading)

compn | 9 Feb 17:52
Picon
Favicon

Re: [RFC][PATCH V2] libmpcodecs/ad_spdif.c check DTS profile

On Thu, 9 Feb 2012 23:31:46 +0900, Naoya OYAMA wrote:
>
>Hi,
>patch updated.

your patch mixes lots of different things together, including cosmetics.

>-        { "aac" , CODEC_ID_AAC    },
>-        { "ac3" , CODEC_ID_AC3    },
>-        { "dca" , CODEC_ID_DTS    },
>-        { "eac3", CODEC_ID_EAC3   },
>-        { "mpa" , CODEC_ID_MP3    },
>-        { "thd" , CODEC_ID_TRUEHD },
>-        { NULL  , 0 }
>+        { "aac"   , CODEC_ID_AAC    },
>+        { "ac3"   , CODEC_ID_AC3    },
>+        { "dca"   , CODEC_ID_DTS    },
>+        { "eac3"  , CODEC_ID_EAC3   },
>+        { "mp3"   , CODEC_ID_MP3    },
>+        { "truehd", CODEC_ID_TRUEHD },
>+        { NULL    , 0 }

changing mpa > mp3 and thd > truehd LGTM.

>Index: etc/codecs.conf
>===================================================================
>--- etc/codecs.conf	(revision 34665)
>+++ etc/codecs.conf	(working copy)
>@@ -5556,7 +5556,7 @@
>   fourcc ".mp1"      ; MP1 (MOV files)
(Continue reading)

Diego Biurrun | 11 Feb 16:04
Picon

Re: [RFC][PATCH V2] libmpcodecs/ad_spdif.c check DTS profile

On Thu, Feb 09, 2012 at 11:31:46PM +0900, Naoya OYAMA wrote:
> patch updated.
> 
> --- libmpcodecs/ad_spdif.c	(revision 34665)
> +++ libmpcodecs/ad_spdif.c	(working copy)
> @@ -135,86 +148,166 @@
> +#if 0
> +    if (!sh->avctx) {
> +        mp_msg(MSGT_DECAUDIO,MSGL_V,
> +               "lavc_ctx:  bit_rate[%d] sample_rate[%d]\n",
> +               lavc_ctx->bit_rate,  lavc_ctx->sample_rate);
> +    } else {
> +        mp_msg(MSGT_DECAUDIO,MSGL_V,
> +               "lavc_ctx:  bit_rate[%d] sample_rate[%d]\n"
> +               "sh->avctx: bit_rate[%d] sample_rate[%d]\n",
> +               lavc_ctx->bit_rate,  lavc_ctx->sample_rate,
> +               sh->avctx->bit_rate, sh->avctx->sample_rate);
> +    }
> +#endif

Don't add more disabled-by-default cruft please.

Diego
Naoya OYAMA | 3 Mar 14:54
Picon

Re: [RFC][PATCH V2] libmpcodecs/ad_spdif.c check DTS profile

Hi,
Thank you for comment.

Patch update.
Then patches was splitting into the following seven.

#1 codec name has modified to match the libavcodec/allcodecs.c.
#2 in the init() to create a lavc.
#3 Internally decode init() using the lavc was created in Step 2., Do
an analysis of stream.
#4 to determine based on lavc->profile the dts, setting appropriate
channels and dtshd_rate and srate.
#5 176400 or 192000 to assign to 48KHz or 44.1KHz srate to determine
whether in truehd.
#6 shall take precedence srate, bps and packet_size of lavc.
#7 cosmetic changes.
Naoya OYAMA | 3 Mar 14:56
Picon

Re: [RFC][PATCH V3_1/7] libmpcodecs/ad_spdif.c check DTS profile

This is patch 1/7
#1 codec name has modified to match the libavcodec/allcodecs.c.
diff -Naur a/etc/codecs.conf b/etc/codecs.conf
--- a/etc/codecs.conf	2012-03-03 16:51:16.105391376 +0900
+++ b/etc/codecs.conf	2012-03-03 19:24:43.165006312 +0900
@@ -5565,7 +5565,7 @@
   fourcc ".mp1"      ; MP1 (MOV files)
   fourcc "MP3 "      ; used in .nsv files
   fourcc "LAME"      ; used in mythtv .nuv files
-  dll    mpa
+  dll    mp3
   driver spdif

 audiocodec spdifthd
@@ -5573,7 +5573,7 @@
   status working
   comment "needs -channels 8"
   fourcc TRHD ; internal MPlayer FourCC
-  dll    thd
+  dll    truehd
   driver spdif

 audiocodec ffwavesynth
diff -Naur a/libmpcodecs/ad_spdif.c b/libmpcodecs/ad_spdif.c
--- a/libmpcodecs/ad_spdif.c	2012-03-03 16:51:02.793391934 +0900
+++ b/libmpcodecs/ad_spdif.c	2012-03-03 19:24:10.589007673 +0900
@@ -84,13 +84,13 @@
     static const struct {
(Continue reading)

Naoya OYAMA | 3 Mar 14:56
Picon

Re: [RFC][PATCH V3_2/7] libmpcodecs/ad_spdif.c check DTS profile

This is patch 2/7
#2 in the init() to create a lavc.
--- a/libmpcodecs/ad_spdif.c	2012-03-03 19:24:10.589007673 +0900
+++ b/libmpcodecs/ad_spdif.c	2012-03-03 20:25:29.500853812 +0900
@@ -25,6 +25,9 @@
 #include "libavformat/avformat.h"
 #include "libavcodec/avcodec.h"
 #include "libavutil/opt.h"
+#include "dec_audio.h"
+#include "help_mp.h"
+#include "libavutil/dict.h"

 static const ad_info_t info = {
     "libavformat/spdifenc audio pass-through decoder.",
@@ -39,6 +42,7 @@
 #define FILENAME_SPDIFENC "spdif"
 #define OUTBUF_SIZE 65536
 struct spdifContext {
+    AVCodecContext  *lavc_ctx;
     AVFormatContext *lavf_ctx;
     int              iec61937_packet_size;
     int              out_buffer_len;
@@ -81,6 +85,7 @@
     int i, x, in_size, srate, bps, *dtshd_rate;
     unsigned char *start;
     double pts;
+    char tmpstr[50];
     static const struct {
(Continue reading)

Naoya OYAMA | 3 Mar 14:57
Picon

Re: [RFC][PATCH V3_3/7] libmpcodecs/ad_spdif.c check DTS profile

This is patch 3/7
#3 Internally decode init() using the lavc was created in Step 2., Do
an analysis of stream.
--- a/libmpcodecs/ad_spdif.c	2012-03-03 20:49:19.844793989 +0900
+++ b/libmpcodecs/ad_spdif.c	2012-03-03 20:46:57.220799954 +0900
@@ -44,10 +44,14 @@
 struct spdifContext {
     AVCodecContext  *lavc_ctx;
     AVFormatContext *lavf_ctx;
+    int              init_buffer_len;
+    int              init_buffer_pos;
+    int              initialized;
     int              iec61937_packet_size;
     int              out_buffer_len;
     int              out_buffer_size;
     uint8_t         *out_buffer;
+    uint8_t          init_buffer[OUTBUF_SIZE];
     uint8_t          pb_buffer[OUTBUF_SIZE];
 };

@@ -82,7 +86,7 @@

 static int init(sh_audio_t *sh)
 {
-    int i, x, in_size, srate, bps, *dtshd_rate;
+    int i, x, in_size, srate, bps, counter_max, *dtshd_rate;
     unsigned char *start;
     double pts;
(Continue reading)

Naoya OYAMA | 3 Mar 14:58
Picon

Re: [RFC][PATCH V3_4/7] libmpcodecs/ad_spdif.c check DTS profile

This is patch 4/7
#4 to determine based on lavc->profile the dts, setting appropriate
channels and dtshd_rate and srate.
--- a/libmpcodecs/ad_spdif.c	2012-03-03 20:50:44.548790446 +0900
+++ b/libmpcodecs/ad_spdif.c	2012-03-03 21:00:14.236766622 +0900
@@ -261,19 +261,42 @@
         sh->channels                    = 2;
         sh->i_bps                       = bps;
         break;
-    case CODEC_ID_DTS: // FORCE USE DTS-HD
+    case CODEC_ID_DTS:
         opt = av_opt_find(&lavf_ctx->oformat->priv_class,
                           "dtshd_rate", NULL, 0, 0);
         if (!opt)
             goto fail;
         dtshd_rate                      = (int*)(((uint8_t*)lavf_ctx->priv_data) +
                                           opt->offset);
-        *dtshd_rate                     = 192000*4;
-        spdif_ctx->iec61937_packet_size = 32768;
         sh->sample_format               = AF_FORMAT_IEC61937_LE;
-        sh->samplerate                  = 192000; // DTS core require 48000
-        sh->channels                    = 2*4;
         sh->i_bps                       = bps;
+        switch (lavc_ctx->profile) {
+        case FF_PROFILE_DTS_HD_HRA:
+            *dtshd_rate                     = 192000;
+            spdif_ctx->iec61937_packet_size = 8192;
+            sh->samplerate                  = 192000;
(Continue reading)

Naoya OYAMA | 3 Mar 14:59
Picon

Re: [RFC][PATCH V3_5/7] libmpcodecs/ad_spdif.c check DTS profile

This is patch 5/7
#5 176400 or 192000 to assign to 48KHz or 44.1KHz srate to determine
whether in truehd.
--- a/libmpcodecs/ad_spdif.c	2012-03-03 21:02:24.536761172 +0900
+++ b/libmpcodecs/ad_spdif.c	2012-03-03 21:26:06.884701687 +0900
@@ -315,9 +315,21 @@
     case CODEC_ID_TRUEHD:
         spdif_ctx->iec61937_packet_size = 61440;
         sh->sample_format               = AF_FORMAT_IEC61937_LE;
-        sh->samplerate                  = 192000;
         sh->channels                    = 8;
         sh->i_bps                       = bps;
+        switch (srate) {
+        case 44100:
+        case 88200:
+        case 176400:
+            sh->samplerate = 176400;
+            break;
+        case 48000:
+        case 96000:
+        case 192000:
+        default:
+            sh->samplerate = 192000;
+            break;
+        }
         break;
     default:
         break;
(Continue reading)

Naoya OYAMA | 3 Mar 14:59
Picon

Re: [RFC][PATCH V3_6/7] libmpcodecs/ad_spdif.c check DTS profile

This is patch 6/7
#6 shall take precedence srate, bps and packet_size of lavc.
--- a/libmpcodecs/ad_spdif.c	2012-03-03 21:30:19.828691107 +0900
+++ b/libmpcodecs/ad_spdif.c	2012-03-03 21:36:25.688675806 +0900
@@ -86,9 +86,7 @@

 static int init(sh_audio_t *sh)
 {
-    int i, x, in_size, srate, bps, counter_max, *dtshd_rate;
-    unsigned char *start;
-    double pts;
+    int i, x, srate, bps, counter_max, *dtshd_rate;
     char tmpstr[50];
     static const struct {
         const char *name; enum CodecID id;
@@ -220,42 +218,35 @@
     }
     if (x <= 0)
         goto fail;
-
-    // get sample_rate & bitrate from parser
-    bps = srate = 0;
-    x = ds_get_packet_pts(sh->ds, &start, &pts);
-    in_size = x;
-    if (x <= 0) {
-        pts = MP_NOPTS_VALUE;
-        x = 0;
-    }
(Continue reading)

Naoya OYAMA | 3 Mar 15:00
Picon

Re: [RFC][PATCH V3_7/7] libmpcodecs/ad_spdif.c check DTS profile

This is patch 7/7
#7 cosmetic changes.
--- a/libmpcodecs/ad_spdif.c	2012-03-03 21:40:56.232664490 +0900
+++ b/libmpcodecs/ad_spdif.c	2012-03-03 21:51:52.784637031 +0900
@@ -99,13 +99,13 @@
         { "truehd", CODEC_ID_TRUEHD },
         { NULL    , 0 }
     };
-    AVFormatContext     *lavf_ctx  = NULL;
-    AVStream            *stream    = NULL;
-    const AVOption      *opt       = NULL;
-    struct spdifContext *spdif_ctx = NULL;
     AVCodecContext      *lavc_ctx   = NULL;
     AVCodec             *lavc_codec = NULL;
     AVDictionary        *opts       = NULL;
+    AVFormatContext     *lavf_ctx   = NULL;
+    AVStream            *stream     = NULL;
+    const AVOption      *opt        = NULL;
+    struct spdifContext *spdif_ctx  = NULL;

     spdif_ctx = av_mallocz(sizeof(*spdif_ctx));
     if (!spdif_ctx)
@@ -179,7 +179,7 @@
         lavc_ctx->extradata_size = sh->wf->cbSize;
         memcpy(lavc_ctx->extradata, sh->wf + 1,
                lavc_ctx->extradata_size);
-     }
+    }
(Continue reading)

Carl Eugen Hoyos | 3 Mar 23:54
Picon

Re: [RFC][PATCH V2] libmpcodecs/ad_spdif.c check DTS profile

Naoya OYAMA <naoya.oyama <at> gmail.com> writes:

> Patch update.
> Then patches was splitting into the following seven.

I currently cannot test this patch and therefore cannot comment.

Sorry, Carl Eugen

Gmane