comparison mxfenc.c @ 4469:49cf858ac430 libavformat

encode klv fill item length in fixed ber 4 bytes
author bcoudurier
date Fri, 13 Feb 2009 05:33:11 +0000
parents f21c01140f2d
children 1c6dd9d7a634
comparison
equal deleted inserted replaced
4468:d23db4a449ed 4469:49cf858ac430
287 put_byte(pb, len >> 8 * size & 0xff); 287 put_byte(pb, len >> 8 * size & 0xff);
288 } 288 }
289 return 0; 289 return 0;
290 } 290 }
291 291
292 static void klv_encode_ber4_length(ByteIOContext *pb, int len)
293 {
294 put_byte(pb, 0x80 + 3);
295 put_be24(pb, len);
296 }
297
292 /* 298 /*
293 * Get essence container ul index 299 * Get essence container ul index
294 */ 300 */
295 static int mxf_get_essence_container_ul_index(enum CodecID id) 301 static int mxf_get_essence_container_ul_index(enum CodecID id)
296 { 302 {
926 } 932 }
927 933
928 static unsigned klv_fill_size(uint64_t size) 934 static unsigned klv_fill_size(uint64_t size)
929 { 935 {
930 unsigned pad = KAG_SIZE - (size & (KAG_SIZE-1)); 936 unsigned pad = KAG_SIZE - (size & (KAG_SIZE-1));
931 if (pad < 17) // smallest fill item possible 937 if (pad < 20) // smallest fill item possible
932 return pad + KAG_SIZE; 938 return pad + KAG_SIZE;
933 else 939 else
934 return pad & (KAG_SIZE-1); 940 return pad & (KAG_SIZE-1);
935 } 941 }
936 942
1059 static void mxf_write_klv_fill(AVFormatContext *s) 1065 static void mxf_write_klv_fill(AVFormatContext *s)
1060 { 1066 {
1061 unsigned pad = klv_fill_size(url_ftell(s->pb)); 1067 unsigned pad = klv_fill_size(url_ftell(s->pb));
1062 if (pad) { 1068 if (pad) {
1063 put_buffer(s->pb, klv_fill_key, 16); 1069 put_buffer(s->pb, klv_fill_key, 16);
1064 pad -= 16; 1070 pad -= 16 + 4;
1065 pad -= klv_ber_length(pad); 1071 klv_encode_ber4_length(s->pb, pad);
1066 klv_encode_ber_length(s->pb, pad);
1067 for (; pad > 7; pad -= 8)
1068 put_be64(s->pb, 0);
1069 for (; pad; pad--) 1072 for (; pad; pad--)
1070 put_byte(s->pb, 0); 1073 put_byte(s->pb, 0);
1071 assert(!(url_ftell(s->pb) & (KAG_SIZE-1))); 1074 assert(!(url_ftell(s->pb) & (KAG_SIZE-1)));
1072 } 1075 }
1073 } 1076 }