Ticket #3233: 0001-Fix-detecting-ATRAC3-audio-from-MPS-files.patch

File 0001-Fix-detecting-ATRAC3-audio-from-MPS-files.patch, 3.3 KB (added by Misty De Meo, 9 years ago)

Fix parsing of PSP video with ATRAC-3 audio when no PSMF header is present

  • libavformat/mpeg.c

    From de27de9d61cc6efeedd524275c574abd1ae76d7e Mon Sep 17 00:00:00 2001
    From: Misty De Meo <mistydemeo@gmail.com>
    Date: Thu, 21 Dec 2017 23:16:44 +0800
    Subject: [PATCH] Fix detecting ATRAC3 audio from MPS files
    
    ---
     libavformat/mpeg.c | 38 ++++++++++++++------------------------
     libavformat/mpeg.h |  1 +
     2 files changed, 15 insertions(+), 24 deletions(-)
    
    diff --git a/libavformat/mpeg.c b/libavformat/mpeg.c
    index 895c6fb231..a366ece0ed 100644
    a b typedef struct MpegDemuxContext {  
    128128    int sofdec;
    129129    int dvd;
    130130    int imkh_cctv;
    131     int sony_psmf; // true if Play Station Movie file signature is present
    132131#if CONFIG_VOBSUB_DEMUXER
    133132    AVFormatContext *sub_ctx;
    134133    FFDemuxSubtitlesQueue q[32];
    static int mpegps_read_header(AVFormatContext *s)  
    148147    avio_get_str(s->pb, 6, buffer, sizeof(buffer));
    149148    if (!memcmp("IMKH", buffer, 4)) {
    150149        m->imkh_cctv = 1;
    151     } else if (!memcmp("PSMF00", buffer, 6)) {
    152         m->sony_psmf = 1;
    153150    } else if (!memcmp("Sofdec", buffer, 6)) {
    154151        m->sofdec = 1;
    155152    } else
    redo:  
    444441        goto redo;
    445442    }
    446443
    447     if (startcode == PRIVATE_STREAM_1 && !m->sony_psmf) {
     444    if (startcode == PRIVATE_STREAM_1) {
    448445        startcode = avio_r8(s->pb);
    449446        len--;
    450447    }
    redo:  
    544541        else
    545542            request_probe= 1;
    546543        type = AVMEDIA_TYPE_VIDEO;
    547     } else if (startcode == PRIVATE_STREAM_1 && m->sony_psmf) {
    548         uint8_t stream_id;
    549 
    550         if (len < 2)
    551             goto skip;
    552         stream_id = avio_r8(s->pb);
     544    // Sony PSP video with ATRAC-3 audio
     545    } else if (!(startcode & STREAM_TYPE_AUDIO_ATRAC3)) {
    553546        avio_r8(s->pb); // skip padding
    554         len -= 2;
    555         if (!(stream_id & 0xF0)) { // seems like we got an ATRAC stream
    556             /* check if an appropriate stream already exists */
    557             for (i = 0; i < s->nb_streams; i++) {
    558                 st = s->streams[i];
    559                 if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO &&
    560                     st->codec->codec_id == AV_CODEC_ID_ATRAC3P &&
    561                     st->id - 0x1BD0 == (stream_id & 0xF))
    562                     goto found;
    563             }
    564 
    565             startcode = 0x1BD0 + (stream_id & 0xF);
    566             type      = AVMEDIA_TYPE_AUDIO;
    567             codec_id  = AV_CODEC_ID_ATRAC3P;
     547        len--;
     548        for (i = 0; i < s->nb_streams; i++) {
     549            st = s->streams[i];
     550            if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO &&
     551                st->codec->codec_id == AV_CODEC_ID_ATRAC3P &&
     552                st->id - 0x1BD0 == (startcode & 0xF))
     553                goto found;
    568554        }
     555
     556        startcode = 0x1BD0 + (startcode & 0xF);
     557        type      = AVMEDIA_TYPE_AUDIO;
     558        codec_id  = AV_CODEC_ID_ATRAC3P;
    569559    } else if (startcode == PRIVATE_STREAM_2) {
    570560        type = AVMEDIA_TYPE_DATA;
    571561        codec_id = AV_CODEC_ID_DVD_NAV;
  • libavformat/mpeg.h

    diff --git a/libavformat/mpeg.h b/libavformat/mpeg.h
    index 617e36cba8..efbadec8ba 100644
    a b  
    5858#define STREAM_TYPE_VIDEO_CAVS      0x42
    5959
    6060#define STREAM_TYPE_AUDIO_AC3       0x81
     61#define STREAM_TYPE_AUDIO_ATRAC3    0xF0
    6162
    6263static const int lpcm_freq_tab[4] = { 48000, 96000, 44100, 32000 };
    6364