annotate assenc.c @ 5170:80a367a3742c libavformat

Cosmetics, add spaces
author banan
date Thu, 10 Sep 2009 19:12:13 +0000
parents 624979ace06c
children a7e674f70016
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3946
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
1 /*
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
2 * SSA/ASS muxer
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
3 * Copyright (c) 2008 Michael Niedermayer
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
4 *
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
5 * This file is part of FFmpeg.
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
6 *
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
11 *
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
15 * Lesser General Public License for more details.
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
16 *
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
20 */
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
21
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
22 #include "avformat.h"
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
23
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
24 typedef struct ASSContext{
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
25 unsigned int extra_index;
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
26 }ASSContext;
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
27
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
28 static int write_header(AVFormatContext *s)
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
29 {
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
30 ASSContext *ass = s->priv_data;
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
31 AVCodecContext *avctx= s->streams[0]->codec;
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
32 uint8_t *last= NULL;
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
33
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
34 if(s->nb_streams != 1 || avctx->codec_id != CODEC_ID_SSA){
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
35 av_log(s, AV_LOG_ERROR, "Exactly one ASS/SSA stream is needed.\n");
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
36 return -1;
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
37 }
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
38
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
39 while(ass->extra_index < avctx->extradata_size){
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
40 uint8_t *p = avctx->extradata + ass->extra_index;
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
41 uint8_t *end= strchr(p, '\n');
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
42 if(!end) end= avctx->extradata + avctx->extradata_size;
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
43 else end++;
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
44
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
45 put_buffer(s->pb, p, end-p);
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
46 ass->extra_index += end-p;
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
47
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
48 if(last && !memcmp(last, "[Events]", 8))
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
49 break;
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
50 last=p;
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
51 }
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
52
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
53 put_flush_packet(s->pb);
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
54
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
55 return 0;
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
56 }
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
57
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
58 static int write_packet(AVFormatContext *s, AVPacket *pkt)
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
59 {
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
60 put_buffer(s->pb, pkt->data, pkt->size);
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
61
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
62 put_flush_packet(s->pb);
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
63
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
64 return 0;
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
65 }
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
66
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
67 static int write_trailer(AVFormatContext *s)
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
68 {
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
69 ASSContext *ass = s->priv_data;
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
70 AVCodecContext *avctx= s->streams[0]->codec;
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
71
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
72 put_buffer(s->pb, avctx->extradata + ass->extra_index,
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
73 avctx->extradata_size - ass->extra_index);
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
74
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
75 put_flush_packet(s->pb);
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
76
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
77 return 0;
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
78 }
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
79
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
80 AVOutputFormat ass_muxer = {
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
81 "ass",
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
82 NULL_IF_CONFIG_SMALL("SSA/ASS format"),
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
83 NULL,
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
84 "ass,ssa",
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
85 sizeof(ASSContext),
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
86 CODEC_ID_NONE,
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
87 CODEC_ID_NONE,
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
88 write_header,
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
89 write_packet,
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
90 write_trailer,
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
91 .flags = AVFMT_GLOBALHEADER | AVFMT_NOTIMESTAMPS
624979ace06c ASS/SSA muxer.
michael
parents:
diff changeset
92 };