mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2025-12-13 18:40:03 +01:00
ogg/opus: implement header packet skip in chained ogg bitstreams.
This commit is contained in:
@@ -239,10 +239,6 @@ static int ogg_replace_stream(AVFormatContext *s, uint32_t serial, char *magic,
|
|||||||
os->start_trimming = 0;
|
os->start_trimming = 0;
|
||||||
os->end_trimming = 0;
|
os->end_trimming = 0;
|
||||||
|
|
||||||
/* Chained files have extradata as a new packet */
|
|
||||||
if (codec == &ff_opus_codec)
|
|
||||||
os->header = -1;
|
|
||||||
|
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,27 +36,27 @@ struct oggopus_private {
|
|||||||
#define OPUS_SEEK_PREROLL_MS 80
|
#define OPUS_SEEK_PREROLL_MS 80
|
||||||
#define OPUS_HEAD_SIZE 19
|
#define OPUS_HEAD_SIZE 19
|
||||||
|
|
||||||
static int opus_header(AVFormatContext *avf, int idx)
|
static int parse_opus_header(AVFormatContext *avf, AVStream *st, struct ogg_stream *os,
|
||||||
|
struct oggopus_private *priv, uint8_t *packet,
|
||||||
|
size_t psize)
|
||||||
{
|
{
|
||||||
struct ogg *ogg = avf->priv_data;
|
int channels;
|
||||||
struct ogg_stream *os = &ogg->streams[idx];
|
|
||||||
AVStream *st = avf->streams[idx];
|
|
||||||
struct oggopus_private *priv = os->private;
|
|
||||||
uint8_t *packet = os->buf + os->pstart;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (!priv) {
|
if (psize < OPUS_HEAD_SIZE || (AV_RL8(packet + 8) & 0xF0) != 0)
|
||||||
priv = os->private = av_mallocz(sizeof(*priv));
|
|
||||||
if (!priv)
|
|
||||||
return AVERROR(ENOMEM);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (os->flags & OGG_FLAG_BOS) {
|
|
||||||
if (os->psize < OPUS_HEAD_SIZE || (AV_RL8(packet + 8) & 0xF0) != 0)
|
|
||||||
return AVERROR_INVALIDDATA;
|
return AVERROR_INVALIDDATA;
|
||||||
|
|
||||||
st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
|
st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
|
||||||
st->codecpar->codec_id = AV_CODEC_ID_OPUS;
|
st->codecpar->codec_id = AV_CODEC_ID_OPUS;
|
||||||
st->codecpar->ch_layout.nb_channels = AV_RL8(packet + 9);
|
|
||||||
|
channels = AV_RL8(packet + 9);
|
||||||
|
if (st->codecpar->ch_layout.nb_channels &&
|
||||||
|
channels != st->codecpar->ch_layout.nb_channels) {
|
||||||
|
av_log(avf, AV_LOG_ERROR, "Channel change is not supported\n");
|
||||||
|
return AVERROR_PATCHWELCOME;
|
||||||
|
}
|
||||||
|
|
||||||
|
st->codecpar->ch_layout.nb_channels = channels;
|
||||||
|
|
||||||
priv->pre_skip = AV_RL16(packet + 10);
|
priv->pre_skip = AV_RL16(packet + 10);
|
||||||
st->codecpar->initial_padding = priv->pre_skip;
|
st->codecpar->initial_padding = priv->pre_skip;
|
||||||
@@ -65,7 +65,8 @@ static int opus_header(AVFormatContext *avf, int idx)
|
|||||||
/*gain = AV_RL16(packet + 16);*/
|
/*gain = AV_RL16(packet + 16);*/
|
||||||
/*channel_map = AV_RL8 (packet + 18);*/
|
/*channel_map = AV_RL8 (packet + 18);*/
|
||||||
|
|
||||||
if ((ret = ff_alloc_extradata(st->codecpar, os->psize)) < 0)
|
ret = ff_alloc_extradata(st->codecpar, os->psize);
|
||||||
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
memcpy(st->codecpar->extradata, packet, os->psize);
|
memcpy(st->codecpar->extradata, packet, os->psize);
|
||||||
@@ -74,10 +75,29 @@ static int opus_header(AVFormatContext *avf, int idx)
|
|||||||
st->codecpar->seek_preroll = av_rescale(OPUS_SEEK_PREROLL_MS,
|
st->codecpar->seek_preroll = av_rescale(OPUS_SEEK_PREROLL_MS,
|
||||||
st->codecpar->sample_rate, 1000);
|
st->codecpar->sample_rate, 1000);
|
||||||
avpriv_set_pts_info(st, 64, 1, 48000);
|
avpriv_set_pts_info(st, 64, 1, 48000);
|
||||||
|
|
||||||
priv->need_comments = 1;
|
priv->need_comments = 1;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int opus_header(AVFormatContext *avf, int idx)
|
||||||
|
{
|
||||||
|
struct ogg *ogg = avf->priv_data;
|
||||||
|
struct ogg_stream *os = &ogg->streams[idx];
|
||||||
|
AVStream *st = avf->streams[idx];
|
||||||
|
struct oggopus_private *priv = os->private;
|
||||||
|
uint8_t *packet = os->buf + os->pstart;
|
||||||
|
|
||||||
|
if (!priv) {
|
||||||
|
priv = os->private = av_mallocz(sizeof(*priv));
|
||||||
|
if (!priv)
|
||||||
|
return AVERROR(ENOMEM);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (os->flags & OGG_FLAG_BOS)
|
||||||
|
return parse_opus_header(avf, st, os, priv, packet, os->psize);
|
||||||
|
|
||||||
if (priv->need_comments) {
|
if (priv->need_comments) {
|
||||||
if (os->psize < 8 || memcmp(packet, "OpusTags", 8))
|
if (os->psize < 8 || memcmp(packet, "OpusTags", 8))
|
||||||
return AVERROR_INVALIDDATA;
|
return AVERROR_INVALIDDATA;
|
||||||
@@ -125,6 +145,19 @@ static int opus_packet(AVFormatContext *avf, int idx)
|
|||||||
return AVERROR_INVALIDDATA;
|
return AVERROR_INVALIDDATA;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (os->psize > 8 && !memcmp(packet, "OpusHead", 8)) {
|
||||||
|
ret = parse_opus_header(avf, st, os, priv, packet, os->psize);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (os->psize > 8 && !memcmp(packet, "OpusTags", 8)) {
|
||||||
|
priv->need_comments = 0;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
if ((!os->lastpts || os->lastpts == AV_NOPTS_VALUE) && !(os->flags & OGG_FLAG_EOS)) {
|
if ((!os->lastpts || os->lastpts == AV_NOPTS_VALUE) && !(os->flags & OGG_FLAG_EOS)) {
|
||||||
int seg, d;
|
int seg, d;
|
||||||
int duration;
|
int duration;
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ Stream ID: 0, frame PTS: 3528, metadata: N/A
|
|||||||
Stream ID: 0, packet PTS: 4488, packet DTS: 4488
|
Stream ID: 0, packet PTS: 4488, packet DTS: 4488
|
||||||
Stream ID: 0, frame PTS: 4488, metadata: N/A
|
Stream ID: 0, frame PTS: 4488, metadata: N/A
|
||||||
Stream ID: 0, packet PTS: -312, packet DTS: -312
|
Stream ID: 0, packet PTS: -312, packet DTS: -312
|
||||||
Stream ID: 0, new metadata: encoder=Lavc61.19.100 libopus;Lavc61.19.100 libopus:title=First Stream;Second Stream
|
|
||||||
Stream ID: 0, frame PTS: -312, metadata: N/A
|
Stream ID: 0, frame PTS: -312, metadata: N/A
|
||||||
Stream ID: 0, packet PTS: 648, packet DTS: 648
|
Stream ID: 0, packet PTS: 648, packet DTS: 648
|
||||||
Stream ID: 0, frame PTS: 648, metadata: N/A
|
Stream ID: 0, frame PTS: 648, metadata: N/A
|
||||||
|
|||||||
Reference in New Issue
Block a user