aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat/ttaenc.c
diff options
context:
space:
mode:
authorJames Almer <jamrial@gmail.com>2017-11-20 17:43:23 -0300
committerJames Almer <jamrial@gmail.com>2017-11-24 15:05:35 -0300
commitfa4121507ca426d3640268cb87c8c1bc547a6103 (patch)
treef2ab8ca565ad9be502e4f5e5ed6314b43c5d7230 /libavformat/ttaenc.c
parente97667c82f4c3ed813269383f8ea825ffb96204f (diff)
downloadffmpeg-fa4121507ca426d3640268cb87c8c1bc547a6103.tar.gz
avformat/ttaenc: add tta_init()
Signed-off-by: James Almer <jamrial@gmail.com>
Diffstat (limited to 'libavformat/ttaenc.c')
-rw-r--r--libavformat/ttaenc.c32
1 files changed, 22 insertions, 10 deletions
diff --git a/libavformat/ttaenc.c b/libavformat/ttaenc.c
index b05705b6b6..add15873d0 100644
--- a/libavformat/ttaenc.c
+++ b/libavformat/ttaenc.c
@@ -35,16 +35,17 @@ typedef struct TTAMuxContext {
int last_frame;
} TTAMuxContext;
-static int tta_write_header(AVFormatContext *s)
+static int tta_init(AVFormatContext *s)
{
TTAMuxContext *tta = s->priv_data;
- AVCodecParameters *par = s->streams[0]->codecpar;
- int ret;
+ AVCodecParameters *par;
if (s->nb_streams != 1) {
av_log(s, AV_LOG_ERROR, "Only one stream is supported\n");
return AVERROR(EINVAL);
}
+ par = s->streams[0]->codecpar;
+
if (par->codec_id != AV_CODEC_ID_TTA) {
av_log(s, AV_LOG_ERROR, "Unsupported codec\n");
return AVERROR(EINVAL);
@@ -54,6 +55,23 @@ static int tta_write_header(AVFormatContext *s)
return AVERROR_INVALIDDATA;
}
+ /* Prevent overflow */
+ if (par->sample_rate > 0x7FFFFFu) {
+ av_log(s, AV_LOG_ERROR, "Sample rate too large\n");
+ return AVERROR(EINVAL);
+ }
+ tta->frame_size = par->sample_rate * 256 / 245;
+ avpriv_set_pts_info(s->streams[0], 64, 1, par->sample_rate);
+
+ return 0;
+}
+
+static int tta_write_header(AVFormatContext *s)
+{
+ TTAMuxContext *tta = s->priv_data;
+ AVCodecParameters *par = s->streams[0]->codecpar;
+ int ret;
+
if ((ret = avio_open_dyn_buf(&tta->seek_table)) < 0)
return ret;
@@ -66,13 +84,6 @@ static int tta_write_header(AVFormatContext *s)
avio_wl16(s->pb, par->channels);
avio_wl16(s->pb, par->bits_per_raw_sample);
avio_wl32(s->pb, par->sample_rate);
- /* Prevent overflow */
- if (par->sample_rate > 0x7FFFFFu) {
- av_log(s, AV_LOG_ERROR, "Sample rate too large\n");
- return AVERROR(EINVAL);
- }
- tta->frame_size = par->sample_rate * 256 / 245;
- avpriv_set_pts_info(s->streams[0], 64, 1, par->sample_rate);
return 0;
}
@@ -167,6 +178,7 @@ AVOutputFormat ff_tta_muxer = {
.priv_data_size = sizeof(TTAMuxContext),
.audio_codec = AV_CODEC_ID_TTA,
.video_codec = AV_CODEC_ID_NONE,
+ .init = tta_init,
.write_header = tta_write_header,
.write_packet = tta_write_packet,
.write_trailer = tta_write_trailer,