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 {
|
| 128 | 128 | int sofdec; |
| 129 | 129 | int dvd; |
| 130 | 130 | int imkh_cctv; |
| 131 | | int sony_psmf; // true if Play Station Movie file signature is present |
| 132 | 131 | #if CONFIG_VOBSUB_DEMUXER |
| 133 | 132 | AVFormatContext *sub_ctx; |
| 134 | 133 | FFDemuxSubtitlesQueue q[32]; |
| … |
… |
static int mpegps_read_header(AVFormatContext *s)
|
| 148 | 147 | avio_get_str(s->pb, 6, buffer, sizeof(buffer)); |
| 149 | 148 | if (!memcmp("IMKH", buffer, 4)) { |
| 150 | 149 | m->imkh_cctv = 1; |
| 151 | | } else if (!memcmp("PSMF00", buffer, 6)) { |
| 152 | | m->sony_psmf = 1; |
| 153 | 150 | } else if (!memcmp("Sofdec", buffer, 6)) { |
| 154 | 151 | m->sofdec = 1; |
| 155 | 152 | } else |
| … |
… |
redo:
|
| 444 | 441 | goto redo; |
| 445 | 442 | } |
| 446 | 443 | |
| 447 | | if (startcode == PRIVATE_STREAM_1 && !m->sony_psmf) { |
| | 444 | if (startcode == PRIVATE_STREAM_1) { |
| 448 | 445 | startcode = avio_r8(s->pb); |
| 449 | 446 | len--; |
| 450 | 447 | } |
| … |
… |
redo:
|
| 544 | 541 | else |
| 545 | 542 | request_probe= 1; |
| 546 | 543 | 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)) { |
| 553 | 546 | 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; |
| 568 | 554 | } |
| | 555 | |
| | 556 | startcode = 0x1BD0 + (startcode & 0xF); |
| | 557 | type = AVMEDIA_TYPE_AUDIO; |
| | 558 | codec_id = AV_CODEC_ID_ATRAC3P; |
| 569 | 559 | } else if (startcode == PRIVATE_STREAM_2) { |
| 570 | 560 | type = AVMEDIA_TYPE_DATA; |
| 571 | 561 | codec_id = AV_CODEC_ID_DVD_NAV; |
diff --git a/libavformat/mpeg.h b/libavformat/mpeg.h
index 617e36cba8..efbadec8ba 100644
|
a
|
b
|
|
| 58 | 58 | #define STREAM_TYPE_VIDEO_CAVS 0x42 |
| 59 | 59 | |
| 60 | 60 | #define STREAM_TYPE_AUDIO_AC3 0x81 |
| | 61 | #define STREAM_TYPE_AUDIO_ATRAC3 0xF0 |
| 61 | 62 | |
| 62 | 63 | static const int lpcm_freq_tab[4] = { 48000, 96000, 44100, 32000 }; |
| 63 | 64 | |