It looks like my previous email has been scrubbed. Therefore, I resubmit it in another thread. Sorry for that!

----------------------------------------------

Hello crews,
I would like to have a support for decoding/demuxing Atrac3+ streams from PSMF (Playstation movie format). Although decoding/demuxing of video streams currently does currently work, audio streams stay still unaccesible. I'm ready to undertake this task but I need a liitle bit help (see below).
PSMF BACKGROUND:
PSMF container can be seen as an extension of MPEG-TS, see here: http://wiki.multimedia.cx/index.php?title=PSMF <https://3c.gmx.net/mail/client/dereferrer?redirectUrl=http%3A%2F%2Fwiki.multimedia.cx%2Findex.php%3Ftitle%3DPSMF> In the current FFMpeg, PSMF will be (mis)-identified as MPEG-TS stream. Atrac Audio is carried out in PRIVATE_STREAM_1 packets. Their format is proprietary but rather simple to understand. Atrac3+ audio streams are delivered inside of packets of the same size, usually 2048 bytes. They usually contain several audio frames. Frames can be splitted across two packets and need to be stitched together in the demuxer.
Now my questions:
1) what's the proper code to be extended? I attached a very draft patch that extends the MPEG demuxer. Is it the right place or should I look for any other? 2) how to deal with multiply frames in a packet? Could you point me to a working example? 3) audio frames can be splitted into two parts and sent with two different packets in the case audio frame size is not an integral of 2048 bytes. It means the demuxer should save the first part in a temporary location, wait for the 2nd part and then concatenate these two parts together. Is there any API or working examples doing that I could look into? I did never implemented a demuxer of such a complexity so I would greatly appreciate any help.
Thank you in advance!
Best regards
Maxim
>From b3013e56b0251d7e1a04191dfaa60ded3431bb23 Mon Sep 17 00:00:00 2001
From: Maxim Poliakovski <maximumspat...@googlemail.com>
Date: Mon, 24 Nov 2014 01:20:21 +0100
Subject: [PATCH 2/2] mpeg: add experimental support for PSMF audio.

---
 libavformat/mpeg.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 57 insertions(+), 4 deletions(-)

diff --git a/libavformat/mpeg.c b/libavformat/mpeg.c
index 827a3c2..fbd5a25 100644
--- a/libavformat/mpeg.c
+++ b/libavformat/mpeg.c
@@ -22,6 +22,7 @@
 #include "avformat.h"
 #include "internal.h"
 #include "mpeg.h"
+#include "oma.h"
 
 #if CONFIG_VOBSUB_DEMUXER
 # include "subtitles.h"
@@ -434,10 +435,10 @@ redo:
         goto redo;
     }
 
-    if (startcode == PRIVATE_STREAM_1) {
-        startcode = avio_r8(s->pb);
-        len--;
-    }
+    //if (startcode == PRIVATE_STREAM_1) {
+    //    startcode = avio_r8(s->pb);
+    //    len--;
+    //}
     if (len < 0)
         goto error_redo;
     if (dts != AV_NOPTS_VALUE && ppos) {
@@ -534,6 +535,58 @@ redo:
         else
             request_probe= 1;
         type = AVMEDIA_TYPE_VIDEO;
+    } else if (startcode == PRIVATE_STREAM_1) {
+        if (len < 4)
+            goto skip;
+        uint8_t stream_id = avio_r8(s->pb);
+        avio_r8(s->pb); // skip padding
+        size_t bytes_remain = avio_rb16(s->pb);
+        len -= 4;
+        if (!(stream_id & 0xF0)) { // seems like we got an ATRAC stream
+            /* check if an appropriate stream already exists */
+            for (i = 0; i < s->nb_streams; i++) {
+                st = s->streams[i];
+                if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO && st->codec->codec_id == AV_CODEC_ID_ATRAC3P && st->id - 0x1BD0 == (stream_id & 0xF))
+                    goto found;
+            }
+
+            if (len < (bytes_remain + 8))
+                goto skip;
+
+            if (bytes_remain)
+                avio_skip(s->pb, bytes_remain);
+
+            uint16_t hdr_id = avio_rb16(s->pb);
+            uint16_t atrac_config = avio_rb16(s->pb);
+            avio_skip(s->pb, 4); // skip padding bytes
+            len -= 8;
+
+            if (hdr_id == 0x0FD0) {
+                int sample_rate = ff_oma_srate_tab[(atrac_config >> 13) & 7] * 100;
+                int channel_id  = (atrac_config >> 10) & 7;
+                int frame_size  = ((atrac_config & 0x3FF) * 8) + 8;
+
+                if (!channel_id || !sample_rate || !frame_size) {
+                    av_log(s, AV_LOG_ERROR, "Invalid ATRAC packet!\n");
+                    return AVERROR_INVALIDDATA;
+                }
+
+                /* add a new ATRAC audio stream */
+                st = avformat_new_stream(s, NULL);
+                if (!st)
+                    goto skip;
+                st->id                    = 0x1BD0 + (stream_id & 0xF);
+                st->codec->codec_type     = AVMEDIA_TYPE_AUDIO;
+                st->codec->codec_id       = AV_CODEC_ID_ATRAC3P;
+                st->codec->sample_rate    = sample_rate;
+                st->codec->block_align    = frame_size;
+                st->codec->bit_rate       = sample_rate * frame_size * 8 / 2048;
+                st->codec->channels       = ff_oma_chid_to_num_channels[channel_id - 1];
+                st->codec->channel_layout = ff_oma_chid_to_native_layout[channel_id - 1];
+                goto found;
+            }
+            goto skip;
+        }
     } else if (startcode == PRIVATE_STREAM_2) {
         type = AVMEDIA_TYPE_DATA;
         codec_id = AV_CODEC_ID_DVD_NAV;
-- 
1.9.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Reply via email to