comparison mxfenc.c @ 3721:caecb9f780a1 libavformat

import ok'd hunks for mxf muxer
author bcoudurier
date Thu, 14 Aug 2008 21:48:02 +0000
parents
children 75fd6b0b1356
comparison
equal deleted inserted replaced
3720:1968303c7566 3721:caecb9f780a1
1 /*
2 * MXF muxer
3 * Copyright (c) 2008 GUCAS, Zhentan Feng <spyfeng at gmail dot com>
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /*
23 * References
24 * SMPTE 336M KLV Data Encoding Protocol Using Key-Length-Value
25 * SMPTE 377M MXF File Format Specifications
26 * SMPTE 379M MXF Generic Container
27 * SMPTE 381M Mapping MPEG Streams into the MXF Generic Container
28 * SMPTE RP210: SMPTE Metadata Dictionary
29 * SMPTE RP224: Registry of SMPTE Universal Labels
30 */
31
32 //#define DEBUG
33
34 static const MXFCodecUL *mxf_get_essence_container_ul(enum CodecID type)
35 {
36 const MXFCodecUL *uls = mxf_essence_container_uls;
37 while (uls->id != CODEC_ID_NONE) {
38 if (uls->id == type)
39 break;
40 uls++;
41 }
42 return uls;
43 }
44
45 static void mxf_free(AVFormatContext *s)
46 {
47 MXFContext *mxf = s->priv_data;
48 AVStream *st;
49 int i;
50
51 av_freep(&mxf->reference.identification);
52 av_freep(mxf->reference.package);
53 av_freep(&mxf->reference.package);
54 av_freep(&mxf->reference.content_storage);
55 for (i = 0; i < s->nb_streams; i++) {
56 st = s->streams[i];
57 av_freep(&st->priv_data);
58 }
59 av_freep(mxf->reference.sub_desc);
60 av_freep(&mxf->reference.sub_desc);
61 av_freep(&mxf->reference.mul_desc);
62 av_freep(&mxf->essence_container_uls);
63 }
64
65 static const MXFDataDefinitionUL *mxf_get_data_definition_ul(enum CodecType type)
66 {
67 const MXFDataDefinitionUL *uls = mxf_data_definition_uls;
68 while (uls->type != CODEC_TYPE_DATA) {
69 if (type == uls->type)
70 break;
71 uls ++;
72 }
73 return uls;
74 }
75
76 static int mux_write_packet(AVFormatContext *s, AVPacket *pkt)
77 {
78 ByteIOContext *pb = s->pb;
79 AVStream *st = s->streams[pkt->stream_index];
80 MXFStreamContext *sc = st->priv_data;
81
82 put_buffer(pb, sc->track_essence_element_key, 16); // write key
83 klv_encode_ber_length(pb, pkt->size); // write length
84 put_buffer(pb, pkt->data, pkt->size); // write value
85
86 put_flush_packet(pb);
87 return 0;
88 }
89
90 AVOutputFormat mxf_muxer = {
91 "mxf",
92 NULL_IF_CONFIG_SMALL("Material eXchange Format"),
93 NULL,
94 "mxf",
95 sizeof(MXFContext),
96 CODEC_ID_PCM_S16LE,
97 CODEC_ID_MPEG2VIDEO,
98 mux_write_header,
99 mux_write_packet,
100 mux_write_footer,
101 };