[MPlayer-cvslog] r34191 - in trunk: Makefile configure etc/codecs.conf libaf/af_format.h libaf/format.c libao2/ao_alsa.c libmpcodecs/ad.c libmpcodecs/ad_spdif.c

diego subversion at mplayerhq.hu
Wed Oct 12 19:23:10 CEST 2011


Author: diego
Date: Wed Oct 12 19:23:08 2011
New Revision: 34191

Log:
S/PDIF passthrough decoder

patch by Naoya OYAMA, naoya.oyama gmail com

Added:
   trunk/libmpcodecs/ad_spdif.c
Modified:
   trunk/Makefile
   trunk/configure
   trunk/etc/codecs.conf
   trunk/libaf/af_format.h
   trunk/libaf/format.c
   trunk/libao2/ao_alsa.c
   trunk/libmpcodecs/ad.c

Modified: trunk/Makefile
==============================================================================
--- trunk/Makefile	Wed Oct 12 13:38:10 2011	(r34190)
+++ trunk/Makefile	Wed Oct 12 19:23:08 2011	(r34191)
@@ -73,6 +73,7 @@ SRCS_COMMON-$(FFMPEG)                += 
                                         av_opts.c                   \
                                         libaf/af_lavcresample.c     \
                                         libmpcodecs/ad_ffmpeg.c     \
+                                        libmpcodecs/ad_spdif.c      \
                                         libmpcodecs/vd_ffmpeg.c     \
                                         libmpcodecs/vf_geq.c        \
                                         libmpcodecs/vf_lavc.c       \

Modified: trunk/configure
==============================================================================
--- trunk/configure	Wed Oct 12 13:38:10 2011	(r34190)
+++ trunk/configure	Wed Oct 12 19:23:08 2011	(r34191)
@@ -8133,8 +8133,10 @@ cat > $TMPH << EOF
    */
 #define CONFIG_FAKE_MONO 1
 
-/* set up max. outburst. use 65536 for ALSA 0.5, for others 16384 is enough */
-#define MAX_OUTBURST 65536
+/* set up max. outburst. use 131072 for TrueHD SPDIF pass-through,
+ * use 65536 for ALSA 0.5, for others 16384 is enough
+ */
+#define MAX_OUTBURST 131072
 
 /* set up audio OUTBURST. Do not change this! */
 #define OUTBURST 512

Modified: trunk/etc/codecs.conf
==============================================================================
--- trunk/etc/codecs.conf	Wed Oct 12 13:38:10 2011	(r34190)
+++ trunk/etc/codecs.conf	Wed Oct 12 19:23:08 2011	(r34191)
@@ -3,7 +3,7 @@
 ;  Before editing this file, please read DOCS/tech/codecs.conf.txt !
 ;=============================================================================
 
-release 20110311
+release 20111012
 
 ;=============================================================================
 ;                   VIDEO CODECS
@@ -5229,3 +5229,62 @@ audiocodec uleaddva
   format 0x216
   driver acm
   dll "dvacm.acm"
+
+audiocodec spdifaac
+  info "libavformat/spdifenc AAC pass-through decoder"
+  status working
+  comment "for AAC hardware decoders"
+  fourcc MP4A
+  dll    aac
+  driver spdif
+
+audiocodec spdifac3
+  info "libavformat/spdifenc AC-3 pass-through decoder"
+  status working
+  comment "for AC-3 hardware decoders"
+  format 0x2000      ; AC-3
+  format 0x332D6361  ; AC-3 in MP4
+  fourcc dnet        ; AC-3
+  dll    ac3
+  driver spdif
+
+audiocodec spdifeac3
+  info "libavformat/spdifenc E-AC-3 pass-through decoder"
+  status working
+  comment "for E-AC-3 hardware decoders"
+  fourcc EAC3        ; E-AC-3
+  dll    eac3
+  driver spdif
+
+audiocodec spdifdts
+  info "libavformat/spdifenc DTS pass-through decoder"
+  status working
+  comment "for DTS hardware decoders"
+  format 0x2001
+  format 0x86
+  dll    dca
+  driver spdif
+
+audiocodec spdifmpa
+  info "libavformat/spdifenc MPEG AUDIO BC pass-through decoder"
+  status untested
+  comment "for MPEG AUDIO BC hardware decoders"
+  format 0x50        ; layer-1 && layer-2
+  format 0x55        ; layer-3
+  format 0x5500736d  ; "ms\0\x55" older MP3 fcc (MOV files)
+  format 0x5000736d  ; "ms\0\x50" older MP2 fcc (MOV files)
+  fourcc ".mp3"      ; CBR/VBR MP3 (MOV files)
+  fourcc ".mp2"      ; MP2 (MOV files)
+  fourcc ".mp1"      ; MP1 (MOV files)
+  fourcc "MP3 "      ; used in .nsv files
+  fourcc "LAME"      ; used in mythtv .nuv files
+  dll    mpa
+  driver spdif
+
+audiocodec spdifthd
+  info "libavformat/spdifenc Dolby TrueHD pass-through decoder"
+  status working
+  comment "for Dolby TrueHD hardware decoders"
+  fourcc "TRHD"
+  dll    thd
+  driver spdif

Modified: trunk/libaf/af_format.h
==============================================================================
--- trunk/libaf/af_format.h	Wed Oct 12 13:38:10 2011	(r34190)
+++ trunk/libaf/af_format.h	Wed Oct 12 19:23:08 2011	(r34191)
@@ -61,6 +61,7 @@
 #define AF_FORMAT_MPEG2		(3<<6) // MPEG(2) audio
 #define AF_FORMAT_AC3		(4<<6) // Dolby Digital AC3
 #define AF_FORMAT_IMA_ADPCM	(5<<6)
+#define AF_FORMAT_IEC61937      (6<<6)
 #define AF_FORMAT_SPECIAL_MASK	(7<<6)
 
 // PREDEFINED formats
@@ -86,6 +87,9 @@
 #define AF_FORMAT_AC3_LE	(AF_FORMAT_AC3|AF_FORMAT_16BIT|AF_FORMAT_LE)
 #define AF_FORMAT_AC3_BE	(AF_FORMAT_AC3|AF_FORMAT_16BIT|AF_FORMAT_BE)
 
+#define AF_FORMAT_IEC61937_LE   (AF_FORMAT_IEC61937|AF_FORMAT_16BIT|AF_FORMAT_LE)
+#define AF_FORMAT_IEC61937_BE   (AF_FORMAT_IEC61937|AF_FORMAT_16BIT|AF_FORMAT_BE)
+
 #if HAVE_BIGENDIAN
 #define AF_FORMAT_U16_NE AF_FORMAT_U16_BE
 #define AF_FORMAT_S16_NE AF_FORMAT_S16_BE
@@ -95,6 +99,7 @@
 #define AF_FORMAT_S32_NE AF_FORMAT_S32_BE
 #define AF_FORMAT_FLOAT_NE AF_FORMAT_FLOAT_BE
 #define AF_FORMAT_AC3_NE AF_FORMAT_AC3_BE
+#define AF_FORMAT_IEC61937_NE AF_FORMAT_IEC61937_BE
 #else
 #define AF_FORMAT_U16_NE AF_FORMAT_U16_LE
 #define AF_FORMAT_S16_NE AF_FORMAT_S16_LE
@@ -104,11 +109,13 @@
 #define AF_FORMAT_S32_NE AF_FORMAT_S32_LE
 #define AF_FORMAT_FLOAT_NE AF_FORMAT_FLOAT_LE
 #define AF_FORMAT_AC3_NE AF_FORMAT_AC3_LE
+#define AF_FORMAT_IEC61937_NE AF_FORMAT_IEC61937_LE
 #endif
 
 #define AF_FORMAT_UNKNOWN (-1)
 
 #define AF_FORMAT_IS_AC3(fmt) (((fmt) & AF_FORMAT_SPECIAL_MASK) == AF_FORMAT_AC3)
+#define AF_FORMAT_IS_IEC61937(fmt) (((fmt) & AF_FORMAT_SPECIAL_MASK) == AF_FORMAT_IEC61937)
 
 int af_str2fmt(const char *str);
 int af_str2fmt_short(const char *str);

Modified: trunk/libaf/format.c
==============================================================================
--- trunk/libaf/format.c	Wed Oct 12 13:38:10 2011	(r34190)
+++ trunk/libaf/format.c	Wed Oct 12 19:23:08 2011	(r34191)
@@ -52,6 +52,9 @@ int af_str2fmt(const char* str)
   if(strstr(str,"mpeg2") || strstr(str,"MPEG2")){
     format |= AF_FORMAT_MPEG2; return format;
   }
+  if(strstr(str,"iec61937") || strstr(str,"IEC61937")){
+    format |= AF_FORMAT_IEC61937 | AF_FORMAT_16BIT; return format;
+  }
   if(strstr(str,"imaadpcm") || strstr(str,"IMAADPCM")){
     format |= AF_FORMAT_IMA_ADPCM; return format;
   }
@@ -121,6 +124,8 @@ char* af_fmt2str(int format, char* str, 
       i+=snprintf(&str[i],size-i,"MPEG-2 "); break;
     case(AF_FORMAT_AC3):
       i+=snprintf(&str[i],size-i,"AC3 "); break;
+    case(AF_FORMAT_IEC61937):
+      i+=snprintf(&str[i],size-i,"IEC61937 "); break;
     case(AF_FORMAT_IMA_ADPCM):
       i+=snprintf(&str[i],size-i,"IMA-ADPCM "); break;
     default:
@@ -161,6 +166,9 @@ static struct {
     { "ac3le", AF_FORMAT_AC3_LE },
     { "ac3be", AF_FORMAT_AC3_BE },
     { "ac3ne", AF_FORMAT_AC3_NE },
+    { "iec61937le", AF_FORMAT_IEC61937_LE },
+    { "iec61937be", AF_FORMAT_IEC61937_BE },
+    { "iec61937ne", AF_FORMAT_IEC61937_NE },
     { "imaadpcm", AF_FORMAT_IMA_ADPCM },
 
     { "u8", AF_FORMAT_U8 },

Modified: trunk/libao2/ao_alsa.c
==============================================================================
--- trunk/libao2/ao_alsa.c	Wed Oct 12 13:38:10 2011	(r34190)
+++ trunk/libao2/ao_alsa.c	Wed Oct 12 19:23:08 2011	(r34191)
@@ -121,7 +121,7 @@ static int control(int cmd, void *arg)
       long get_vol, set_vol;
       float f_multi;
 
-      if(AF_FORMAT_IS_AC3(ao_data.format))
+      if(AF_FORMAT_IS_AC3(ao_data.format) || AF_FORMAT_IS_IEC61937(ao_data.format))
 	return CONTROL_TRUE;
 
       if(mixer_channel) {
@@ -361,10 +361,12 @@ static int init(int rate_hz, int channel
 	break;
       case AF_FORMAT_AC3_LE:
       case AF_FORMAT_S16_LE:
+      case AF_FORMAT_IEC61937_LE:
 	alsa_format = SND_PCM_FORMAT_S16_LE;
 	break;
       case AF_FORMAT_AC3_BE:
       case AF_FORMAT_S16_BE:
+      case AF_FORMAT_IEC61937_BE:
 	alsa_format = SND_PCM_FORMAT_S16_BE;
 	break;
       case AF_FORMAT_U32_LE:
@@ -418,9 +420,9 @@ static int init(int rate_hz, int channel
      * while opening the abstract alias for the spdif subdevice
      * 'iec958'
      */
-    if (AF_FORMAT_IS_AC3(format)) {
+    if (AF_FORMAT_IS_AC3(format) || AF_FORMAT_IS_IEC61937(format)) {
 	device.str = "iec958";
-	mp_msg(MSGT_AO,MSGL_V,"alsa-spdif-init: playing AC3, %i channels\n", channels);
+	mp_msg(MSGT_AO,MSGL_V,"alsa-spdif-init: playing AC3/iec61937/iec958, %i channels\n", channels);
     }
   else
         /* in any case for multichannel playback we should select
@@ -469,7 +471,7 @@ static int init(int rate_hz, int channel
 
     if (!alsa_handler) {
       int open_mode = block ? 0 : SND_PCM_NONBLOCK;
-      int isac3 =  AF_FORMAT_IS_AC3(format);
+      int isac3 =  AF_FORMAT_IS_AC3(format) || AF_FORMAT_IS_IEC61937(format);
       //modes = 0, SND_PCM_NONBLOCK, SND_PCM_ASYNC
       if ((err = try_open_device(alsa_device, open_mode, isac3)) < 0)
 	{
@@ -520,6 +522,8 @@ static int init(int rate_hz, int channel
          alsa_format = SND_PCM_FORMAT_S16_LE;
          if (AF_FORMAT_IS_AC3(ao_data.format))
            ao_data.format = AF_FORMAT_AC3_LE;
+         else if (AF_FORMAT_IS_IEC61937(ao_data.format))
+           ao_data.format = AF_FORMAT_IEC61937_LE;
          else
          ao_data.format = AF_FORMAT_S16_LE;
       }

Modified: trunk/libmpcodecs/ad.c
==============================================================================
--- trunk/libmpcodecs/ad.c	Wed Oct 12 13:38:10 2011	(r34190)
+++ trunk/libmpcodecs/ad.c	Wed Oct 12 19:23:08 2011	(r34191)
@@ -56,6 +56,7 @@ extern const ad_functions_t mpcodecs_ad_
 extern const ad_functions_t mpcodecs_ad_realaud;
 extern const ad_functions_t mpcodecs_ad_libdv;
 extern const ad_functions_t mpcodecs_ad_qtaudio;
+extern const ad_functions_t mpcodecs_ad_spdif;
 extern const ad_functions_t mpcodecs_ad_twin;
 extern const ad_functions_t mpcodecs_ad_libmusepack;
 extern const ad_functions_t mpcodecs_ad_libdca;
@@ -75,6 +76,7 @@ const ad_functions_t * const mpcodecs_ad
   &mpcodecs_ad_hwmpa,
 #ifdef CONFIG_FFMPEG
   &mpcodecs_ad_ffmpeg,
+  &mpcodecs_ad_spdif,
 #endif
   &mpcodecs_ad_pcm,
   &mpcodecs_ad_dvdpcm,

Added: trunk/libmpcodecs/ad_spdif.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ trunk/libmpcodecs/ad_spdif.c	Wed Oct 12 19:23:08 2011	(r34191)
@@ -0,0 +1,311 @@
+/*
+ * This file is part of MPlayer.
+ *
+ * MPlayer is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MPlayer is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <string.h>
+
+#include "config.h"
+#include "mp_msg.h"
+#include "ad_internal.h"
+#include "libavformat/avformat.h"
+#include "libavcodec/avcodec.h"
+#include "libavutil/opt.h"
+
+static const ad_info_t info = {
+    "libavformat/spdifenc audio pass-through decoder.",
+    "spdif",
+    "Naoya OYAMA",
+    "Naoya OYAMA",
+    "For ALL hardware decoders"
+};
+
+LIBAD_EXTERN(spdif)
+
+#define FILENAME_SPDIFENC "spdif"
+#define OUTBUF_SIZE 65536
+struct spdifContext {
+    AVFormatContext *lavf_ctx;
+    int              iec61937_packet_size;
+    int              out_buffer_len;
+    int              out_buffer_size;
+    uint8_t         *out_buffer;
+    uint8_t          pb_buffer[OUTBUF_SIZE];
+};
+
+static int read_packet(void *p, uint8_t *buf, int buf_size)
+{
+    // spdifenc does not use read callback.
+    return 0;
+}
+
+static int write_packet(void *p, uint8_t *buf, int buf_size)
+{
+    int len;
+    struct spdifContext *ctx = p;
+
+    len = FFMIN(buf_size, ctx->out_buffer_size -ctx->out_buffer_len);
+    memcpy(&ctx->out_buffer[ctx->out_buffer_len], buf, len);
+    ctx->out_buffer_len += len;
+    return len;
+}
+
+static int64_t seek(void *p, int64_t offset, int whence)
+{
+    // spdifenc does not use seek callback.
+    return 0;
+}
+
+static int preinit(sh_audio_t *sh)
+{
+    sh->samplesize = 2;
+    return 1;
+}
+
+static int init(sh_audio_t *sh)
+{
+    int i, x, in_size, srate, bps, *dtshd_rate;
+    unsigned char *start;
+    double pts;
+    static const struct {
+        const char *name; enum CodecID id;
+    } fmt_id_type[] = {
+        { "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 }
+    };
+    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)
+        goto fail;
+    spdif_ctx->lavf_ctx = avformat_alloc_context();
+    if (!spdif_ctx->lavf_ctx)
+        goto fail;
+
+    sh->context = spdif_ctx;
+    lavf_ctx    = spdif_ctx->lavf_ctx;
+
+    lavf_ctx->oformat = av_guess_format(FILENAME_SPDIFENC, NULL, NULL);
+    if (!lavf_ctx->oformat)
+        goto fail;
+    lavf_ctx->priv_data = av_mallocz(lavf_ctx->oformat->priv_data_size);
+    if (!lavf_ctx->priv_data)
+        goto fail;
+    lavf_ctx->pb = avio_alloc_context(spdif_ctx->pb_buffer, OUTBUF_SIZE, 1, spdif_ctx,
+                            read_packet, write_packet, seek);
+    if (!lavf_ctx->pb)
+        goto fail;
+    stream = av_new_stream(lavf_ctx, 0);
+    if (!stream)
+        goto fail;
+    lavf_ctx->duration   = AV_NOPTS_VALUE;
+    lavf_ctx->start_time = AV_NOPTS_VALUE;
+    for (i = 0; fmt_id_type[i].name; i++) {
+        if (!strcmp(sh->codec->dll, fmt_id_type[i].name)) {
+            lavf_ctx->streams[0]->codec->codec_id = fmt_id_type[i].id;
+            break;
+        }
+    }
+    lavf_ctx->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE;
+    if (AVERROR_PATCHWELCOME == lavf_ctx->oformat->write_header(lavf_ctx)) {
+        mp_msg(MSGT_DECAUDIO,MSGL_INFO,
+               "This codec is not supported by spdifenc.\n");
+        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;
+    }
+    ds_parse(sh->ds, &start, &x, pts, 0);
+    if (x == 0) { // not enough buffer
+        srate = 48000;    //fake value
+        bps   = 768000/8; //fake value
+    } else  if (sh->avctx) {
+        if (sh->avctx->sample_rate < 44100) {
+            mp_msg(MSGT_DECAUDIO,MSGL_INFO,
+                   "This stream sample_rate[%d Hz] may be broken. "
+                   "Force reset 48000Hz.\n",
+                   sh->avctx->sample_rate);
+            srate = 48000; //fake value
+        } else
+            srate = sh->avctx->sample_rate;
+        bps = sh->avctx->bit_rate/8;
+    } else {
+        ;
+    }
+    sh->ds->buffer_pos -= in_size;
+
+    switch (lavf_ctx->streams[0]->codec->codec_id) {
+    case CODEC_ID_AAC:
+        spdif_ctx->iec61937_packet_size = 16384;
+        sh->sample_format               = AF_FORMAT_IEC61937_LE;
+        sh->samplerate                  = srate;
+        sh->channels                    = 2;
+        sh->i_bps                       = bps;
+        break;
+    case CODEC_ID_AC3:
+        spdif_ctx->iec61937_packet_size = 6144;
+        sh->sample_format               = AF_FORMAT_IEC61937_LE;
+        sh->samplerate                  = srate;
+        sh->channels                    = 2;
+        sh->i_bps                       = bps;
+        break;
+    case CODEC_ID_DTS: // FORCE USE DTS-HD
+        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;
+        break;
+    case CODEC_ID_EAC3:
+        spdif_ctx->iec61937_packet_size = 24576;
+        sh->sample_format               = AF_FORMAT_IEC61937_LE;
+        sh->samplerate                  = 192000;
+        sh->channels                    = 2;
+        sh->i_bps                       = bps;
+        break;
+    case CODEC_ID_MP3:
+        spdif_ctx->iec61937_packet_size = 4608;
+        sh->sample_format               = AF_FORMAT_MPEG2;
+        sh->samplerate                  = srate;
+        sh->channels                    = 2;
+        sh->i_bps                       = bps;
+        break;
+    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;
+        break;
+    default:
+        break;
+    }
+
+    return 1;
+
+fail:
+    uninit(sh);
+    return 0;
+}
+
+static int decode_audio(sh_audio_t *sh, unsigned char *buf,
+                        int minlen, int maxlen)
+{
+    struct spdifContext *spdif_ctx = sh->context;
+    AVFormatContext     *lavf_ctx  = spdif_ctx->lavf_ctx;
+    AVPacket            pkt;
+    double              pts;
+    int                 ret, in_size, consumed, x;
+    unsigned char       *start = NULL;
+
+    consumed = spdif_ctx->out_buffer_len  = 0;
+    spdif_ctx->out_buffer_size = maxlen;
+    spdif_ctx->out_buffer      = buf;
+    while (spdif_ctx->out_buffer_len + spdif_ctx->iec61937_packet_size < maxlen
+           && spdif_ctx->out_buffer_len < minlen) {
+        if (sh->ds->eof)
+            break;
+        x = ds_get_packet_pts(sh->ds, &start, &pts);
+        if (x <= 0) {
+            x = 0;
+            ds_parse(sh->ds, &start, &x, MP_NOPTS_VALUE, 0);
+            if (x == 0)
+                continue; // END_NOT_FOUND
+            in_size = x;
+        } else {
+            in_size = x;
+            consumed = ds_parse(sh->ds, &start, &x, pts, 0);
+            if (x == 0) {
+                mp_msg(MSGT_DECAUDIO,MSGL_V,
+                       "start[%p] pkt.size[%d] in_size[%d] consumed[%d] x[%d].\n",
+                       start, pkt.size, in_size, consumed, x);
+                continue; // END_NOT_FOUND
+            }
+            sh->ds->buffer_pos -= in_size - consumed;
+        }
+        av_init_packet(&pkt);
+        pkt.data = start;
+        pkt.size = x;
+        mp_msg(MSGT_DECAUDIO,MSGL_V,
+               "start[%p] pkt.size[%d] in_size[%d] consumed[%d] x[%d].\n",
+               start, pkt.size, in_size, consumed, x);
+        if (pts != MP_NOPTS_VALUE) {
+            sh->pts       = pts;
+            sh->pts_bytes = 0;
+        }
+        ret = lavf_ctx->oformat->write_packet(lavf_ctx, &pkt);
+        if (ret < 0)
+            break;
+    }
+    sh->pts_bytes += spdif_ctx->out_buffer_len;
+    return spdif_ctx->out_buffer_len;
+}
+
+static int control(sh_audio_t *sh, int cmd, void* arg, ...)
+{
+    unsigned char *start;
+    double pts;
+
+    switch (cmd) {
+    case ADCTRL_RESYNC_STREAM:
+    case ADCTRL_SKIP_FRAME:
+        ds_get_packet_pts(sh->ds, &start, &pts);
+        return CONTROL_TRUE;
+    }
+    return CONTROL_UNKNOWN;
+}
+
+static void uninit(sh_audio_t *sh)
+{
+    struct spdifContext *spdif_ctx = sh->context;
+    AVFormatContext     *lavf_ctx  = spdif_ctx->lavf_ctx;
+
+    if (lavf_ctx) {
+        if (lavf_ctx->oformat)
+            lavf_ctx->oformat->write_trailer(lavf_ctx);
+        av_freep(&lavf_ctx->pb);
+        if (lavf_ctx->streams) {
+            av_freep(&lavf_ctx->streams[0]->codec);
+            av_freep(&lavf_ctx->streams[0]->info);
+            av_freep(&lavf_ctx->streams[0]);
+        }
+        av_freep(&lavf_ctx->streams);
+        av_freep(&lavf_ctx->priv_data);
+    }
+    av_freep(&lavf_ctx);
+    av_freep(&spdif_ctx);
+}


More information about the MPlayer-cvslog mailing list