annotate vocenc.c @ 6048:e507a21a9566 libavformat

matroskaenc: Write codec time base as default duration for video tracks. This isn't exactly semantically equivalent, but the field has already been long abused to mean this, and writing it helps in determining a decent cfr time base when transcoding from a mkv where the video codec stores none (VP8).
author conrad
date Mon, 24 May 2010 08:58:19 +0000
parents c7b98381ec2d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
937
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
1 /*
1535
a3fbb2b1fccf split voc.c into vocdec.c and vocenc.c
aurel
parents: 1358
diff changeset
2 * Creative Voice File muxer.
937
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
3 * Copyright (c) 2006 Aurelien Jacobs <aurel@gnuage.org>
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
4 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1172
diff changeset
5 * This file is part of FFmpeg.
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1172
diff changeset
6 *
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1172
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
937
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1172
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
937
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
11 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1172
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
937
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
15 * Lesser General Public License for more details.
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
16 *
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1172
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
2217
06083249909c license header consistency cosmetics
diego
parents: 1694
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
937
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
20 */
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
21
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
22 #include "voc.h"
6033
c7b98381ec2d Move AVCodecTag from riff.h into internal.h.
cehoyos
parents: 5910
diff changeset
23 #include "internal.h"
937
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
24
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
25
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
26 typedef struct voc_enc_context {
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
27 int param_written;
4081
3d6e7901bf05 avoid POSIX reserved _t suffix
aurel
parents: 3908
diff changeset
28 } VocEncContext;
937
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
29
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
30 static int voc_write_header(AVFormatContext *s)
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
31 {
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2382
diff changeset
32 ByteIOContext *pb = s->pb;
937
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
33 const int header_size = 26;
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
34 const int version = 0x0114;
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
35
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
36 if (s->nb_streams != 1
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 4081
diff changeset
37 || s->streams[0]->codec->codec_type != AVMEDIA_TYPE_AUDIO)
2382
863ea27be885 Use AVERROR_PATCHWELCOME instead of AVERROR(ENOTSUP)
ramiro
parents: 2277
diff changeset
38 return AVERROR_PATCHWELCOME;
937
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
39
3764
9cff515fd4c6 voc: add ff_ prefix to some global const data
aurel
parents: 3424
diff changeset
40 put_buffer(pb, ff_voc_magic, sizeof(ff_voc_magic) - 1);
937
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
41 put_le16(pb, header_size);
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
42 put_le16(pb, version);
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
43 put_le16(pb, ~version + 0x1234);
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
44
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
45 return 0;
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
46 }
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
47
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
48 static int voc_write_packet(AVFormatContext *s, AVPacket *pkt)
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
49 {
4081
3d6e7901bf05 avoid POSIX reserved _t suffix
aurel
parents: 3908
diff changeset
50 VocEncContext *voc = s->priv_data;
937
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
51 AVCodecContext *enc = s->streams[0]->codec;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2382
diff changeset
52 ByteIOContext *pb = s->pb;
937
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
53
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
54 if (!voc->param_written) {
1694
bbb1abaa43cb remove now useless codec_tag setting code in voc muxer
aurel
parents: 1679
diff changeset
55 if (enc->codec_tag > 0xFF) {
937
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
56 put_byte(pb, VOC_TYPE_NEW_VOICE_DATA);
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
57 put_le24(pb, pkt->size + 12);
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
58 put_le32(pb, enc->sample_rate);
3908
1d3d17de20ba Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents: 3766
diff changeset
59 put_byte(pb, enc->bits_per_coded_sample);
937
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
60 put_byte(pb, enc->channels);
1694
bbb1abaa43cb remove now useless codec_tag setting code in voc muxer
aurel
parents: 1679
diff changeset
61 put_le16(pb, enc->codec_tag);
937
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
62 put_le32(pb, 0);
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
63 } else {
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
64 if (s->streams[0]->codec->channels > 1) {
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
65 put_byte(pb, VOC_TYPE_EXTENDED);
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
66 put_le24(pb, 4);
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
67 put_le16(pb, 65536-256000000/(enc->sample_rate*enc->channels));
1694
bbb1abaa43cb remove now useless codec_tag setting code in voc muxer
aurel
parents: 1679
diff changeset
68 put_byte(pb, enc->codec_tag);
937
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
69 put_byte(pb, enc->channels - 1);
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
70 }
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
71 put_byte(pb, VOC_TYPE_VOICE_DATA);
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
72 put_le24(pb, pkt->size + 2);
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
73 put_byte(pb, 256 - 1000000 / enc->sample_rate);
1694
bbb1abaa43cb remove now useless codec_tag setting code in voc muxer
aurel
parents: 1679
diff changeset
74 put_byte(pb, enc->codec_tag);
937
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
75 }
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
76 voc->param_written = 1;
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
77 } else {
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
78 put_byte(pb, VOC_TYPE_VOICE_DATA_CONT);
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
79 put_le24(pb, pkt->size);
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
80 }
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
81
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
82 put_buffer(pb, pkt->data, pkt->size);
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
83 return 0;
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
84 }
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
85
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
86 static int voc_write_trailer(AVFormatContext *s)
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
87 {
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2382
diff changeset
88 put_byte(s->pb, 0);
937
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
89 return 0;
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
90 }
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
91
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
92 AVOutputFormat voc_muxer = {
937
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
93 "voc",
3424
7a0230981402 Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents: 2771
diff changeset
94 NULL_IF_CONFIG_SMALL("Creative Voice file format"),
937
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
95 "audio/x-voc",
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
96 "voc",
4081
3d6e7901bf05 avoid POSIX reserved _t suffix
aurel
parents: 3908
diff changeset
97 sizeof(VocEncContext),
937
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
98 CODEC_ID_PCM_U8,
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
99 CODEC_ID_NONE,
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
100 voc_write_header,
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
101 voc_write_packet,
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
102 voc_write_trailer,
3766
f062deeedb8d Change codec_tag type from const struct AVCodecTag ** to const struct AVCodecTag * const *
reimar
parents: 3764
diff changeset
103 .codec_tag=(const AVCodecTag* const []){ff_voc_codec_tags, 0},
937
a887adfe9dc5 add a Creative VOC (de)muxer
aurel
parents:
diff changeset
104 };