summaryrefslogtreecommitdiff
path: root/libavformat/mpegtsenc.c
diff options
context:
space:
mode:
Diffstat (limited to 'libavformat/mpegtsenc.c')
-rw-r--r--libavformat/mpegtsenc.c55
1 files changed, 28 insertions, 27 deletions
diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index 8ef8eebc54..ffbea97633 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -252,7 +252,7 @@ static void mpegts_write_pmt(AVFormatContext *s, MpegTSService *service)
err = 1;
break;
}
- switch (st->codec->codec_id) {
+ switch (st->codecpar->codec_id) {
case AV_CODEC_ID_MPEG1VIDEO:
case AV_CODEC_ID_MPEG2VIDEO:
stream_type = STREAM_TYPE_VIDEO_MPEG2;
@@ -299,9 +299,9 @@ static void mpegts_write_pmt(AVFormatContext *s, MpegTSService *service)
q += 2; /* patched after */
/* write optional descriptors here */
- switch (st->codec->codec_type) {
+ switch (st->codecpar->codec_type) {
case AVMEDIA_TYPE_AUDIO:
- if (st->codec->codec_id == AV_CODEC_ID_AC3 && (ts->flags & MPEGTS_FLAG_SYSTEM_B)) {
+ if (st->codecpar->codec_id == AV_CODEC_ID_AC3 && (ts->flags & MPEGTS_FLAG_SYSTEM_B)) {
*q++ = 0x6a; /* ETSI EN 300 468 AC-3 descriptor */
*q++ = 1;
*q++ = 0x00;
@@ -361,8 +361,8 @@ static void mpegts_write_pmt(AVFormatContext *s, MpegTSService *service)
break;
}
- if (st->codec->extradata_size == 4) {
- memcpy(q, st->codec->extradata, 4);
+ if (st->codecpar->extradata_size == 4) {
+ memcpy(q, st->codecpar->extradata, 4);
q += 4;
} else {
put16(&q, 1); /* page id */
@@ -607,13 +607,13 @@ static int mpegts_write_header(AVFormatContext *s)
ts_st->first_pts_check = 1;
ts_st->cc = 15;
/* update PCR pid by using the first video stream */
- if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO &&
+ if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
service->pcr_pid == 0x1fff) {
service->pcr_pid = ts_st->pid;
pcr_st = st;
}
- if (st->codec->codec_id == AV_CODEC_ID_AAC &&
- st->codec->extradata_size > 0) {
+ if (st->codecpar->codec_id == AV_CODEC_ID_AAC &&
+ st->codecpar->extradata_size > 0) {
AVStream *ast;
ts_st->amux = avformat_alloc_context();
if (!ts_st->amux) {
@@ -631,7 +631,7 @@ static int mpegts_write_header(AVFormatContext *s)
ret = AVERROR(ENOMEM);
goto fail;
}
- ret = avcodec_copy_context(ast->codec, st->codec);
+ ret = avcodec_parameters_copy(ast->codecpar, st->codecpar);
if (ret != 0)
goto fail;
ast->time_base = st->time_base;
@@ -664,14 +664,15 @@ static int mpegts_write_header(AVFormatContext *s)
/* Arbitrary values, PAT/PMT could be written on key frames */
ts->sdt_packet_period = 200;
ts->pat_packet_period = 40;
- if (pcr_st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
- if (!pcr_st->codec->frame_size) {
+ if (pcr_st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
+ int frame_size = av_get_audio_frame_duration2(pcr_st->codecpar, 0);
+ if (!frame_size) {
av_log(s, AV_LOG_WARNING, "frame size not set\n");
service->pcr_packet_period =
- pcr_st->codec->sample_rate / (10 * 512);
+ pcr_st->codecpar->sample_rate / (10 * 512);
} else {
service->pcr_packet_period =
- pcr_st->codec->sample_rate / (10 * pcr_st->codec->frame_size);
+ pcr_st->codecpar->sample_rate / (10 * frame_size);
}
} else {
// max delta PCR 0.1s
@@ -926,19 +927,19 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st,
*q++ = 0x00;
*q++ = 0x01;
private_code = 0;
- if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
- if (st->codec->codec_id == AV_CODEC_ID_DIRAC)
+ if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
+ if (st->codecpar->codec_id == AV_CODEC_ID_DIRAC)
*q++ = 0xfd;
else
*q++ = 0xe0;
- } else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO &&
- (st->codec->codec_id == AV_CODEC_ID_MP2 ||
- st->codec->codec_id == AV_CODEC_ID_MP3 ||
- st->codec->codec_id == AV_CODEC_ID_AAC)) {
+ } else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
+ (st->codecpar->codec_id == AV_CODEC_ID_MP2 ||
+ st->codecpar->codec_id == AV_CODEC_ID_MP3 ||
+ st->codecpar->codec_id == AV_CODEC_ID_AAC)) {
*q++ = 0xc0;
} else {
*q++ = 0xbd;
- if (st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE)
+ if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE)
private_code = 0x20;
}
header_len = 0;
@@ -951,8 +952,8 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st,
header_len += 5;
flags |= 0x40;
}
- if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO &&
- st->codec->codec_id == AV_CODEC_ID_DIRAC) {
+ if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
+ st->codecpar->codec_id == AV_CODEC_ID_DIRAC) {
/* set PES_extension_flag */
pes_extension = 1;
flags |= 0x01;
@@ -971,7 +972,7 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st,
*q++ = len;
val = 0x80;
/* data alignment indicator is required for subtitle data */
- if (st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE)
+ if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE)
val |= 0x04;
*q++ = val;
*q++ = flags;
@@ -984,7 +985,7 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st,
write_pts(q, 1, dts);
q += 5;
}
- if (pes_extension && st->codec->codec_id == AV_CODEC_ID_DIRAC) {
+ if (pes_extension && st->codecpar->codec_id == AV_CODEC_ID_DIRAC) {
flags = 0x01; /* set PES_extension_flag_2 */
*q++ = flags;
*q++ = 0x80 | 0x01; /* marker bit + extension length */
@@ -1068,7 +1069,7 @@ static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt)
}
ts_st->first_pts_check = 0;
- if (st->codec->codec_id == AV_CODEC_ID_H264) {
+ if (st->codecpar->codec_id == AV_CODEC_ID_H264) {
const uint8_t *p = buf, *buf_end = p + size;
uint32_t state = -1;
@@ -1095,7 +1096,7 @@ static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt)
buf = data;
size = pkt->size + 6;
}
- } else if (st->codec->codec_id == AV_CODEC_ID_AAC) {
+ } else if (st->codecpar->codec_id == AV_CODEC_ID_AAC) {
if (pkt->size < 2) {
av_log(s, AV_LOG_ERROR, "AAC packet too short\n");
return AVERROR_INVALIDDATA;
@@ -1129,7 +1130,7 @@ static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt)
}
}
- if (st->codec->codec_type != AVMEDIA_TYPE_AUDIO) {
+ if (st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO) {
// for video and subtitle, write a single pes packet
mpegts_write_pes(s, st, buf, size, pts, dts,
pkt->flags & AV_PKT_FLAG_KEY);