Mercurial > mplayer.hg
comparison DOCS/tech/mpcf.txt @ 17711:8aa18d8e5eb6
add forward_ptr to syncpoint (+0.006% overhead)
give syncpoint and frameheader their own checksums (worst case overhead increase <0.006%)
fix filestructure so that extendability is restored
move index_ptr to the fileend so that index packets arent a special case with their reserved_bytes position
-> all packets follow the same structure now
remove "optional" word from info packets, they are not more optional then index packets
split index packets
note, this is entirely optional and a muxer which has difficulty with it can always output a single index packet
remove the index MUST be at the file end if anywher rule, its not needed anymore as index_ptr will always be at the end
info frames must be keyframes
last info frame is the most correct
comments, flames?
author | michael |
---|---|
date | Wed, 01 Mar 2006 14:19:37 +0000 |
parents | 9a976f1550f1 |
children | ad3cb21e1b18 |
comparison
equal
deleted
inserted
replaced
17710:9a976f1550f1 | 17711:8aa18d8e5eb6 |
---|---|
120 in a compatible way] | 120 in a compatible way] |
121 | 121 |
122 Headers: | 122 Headers: |
123 | 123 |
124 main header: | 124 main header: |
125 main_startcode f(64) | |
126 forward_ptr v | |
127 version v | 125 version v |
128 stream_count v | 126 stream_count v |
129 max_distance v | 127 max_distance v |
130 tmp_pts=0 | 128 tmp_pts=0 |
131 tmp_mul=1 | 129 tmp_mul=1 |
160 data_size_lsb[i]= tmp_size + j; | 158 data_size_lsb[i]= tmp_size + j; |
161 pts_delta[i]= tmp_pts; | 159 pts_delta[i]= tmp_pts; |
162 reserved_count[i]= tmp_res; | 160 reserved_count[i]= tmp_res; |
163 } | 161 } |
164 } | 162 } |
165 reserved_bytes | |
166 checksum u(32) | |
167 | 163 |
168 stream_header: | 164 stream_header: |
169 stream_startcode f(64) | |
170 forward_ptr v | |
171 stream_id v | 165 stream_id v |
172 stream_class v | 166 stream_class v |
173 fourcc vb | 167 fourcc vb |
174 time_base_nom v | 168 time_base_nom v |
175 time_base_denom v | 169 time_base_denom v |
188 }else if(stream_class == audio){ | 182 }else if(stream_class == audio){ |
189 samplerate_nom v | 183 samplerate_nom v |
190 samplerate_denom v | 184 samplerate_denom v |
191 channel_count v | 185 channel_count v |
192 } | 186 } |
193 reserved_bytes | |
194 checksum u(32) | |
195 | 187 |
196 Basic Packets: | 188 Basic Packets: |
197 | 189 |
198 frame: | 190 frame: |
199 frame_code f(8) | 191 frame_code f(8) |
209 if(flags[frame_code]&2){ | 201 if(flags[frame_code]&2){ |
210 coded_stream_flags v | 202 coded_stream_flags v |
211 } | 203 } |
212 for(i=0; i<reserved_count[frame_code]; i++) | 204 for(i=0; i<reserved_count[frame_code]; i++) |
213 reserved v | 205 reserved v |
214 if (after_syncpoint){ | 206 if(stream_flags&4){ |
215 syncpoint_checksum u(32) | 207 checksum u(32) |
216 } | 208 } |
217 data | 209 data |
218 | 210 |
219 index: | 211 index: |
220 index_startcode f(64) | |
221 forward_ptr v | |
222 max_pts v | 212 max_pts v |
213 syncpoint_start v | |
223 syncpoints v | 214 syncpoints v |
224 for(i=0; i<syncpoints; i++){ | 215 for(i=syncpoint_start; i<syncpoints; i++){ |
225 syncpoint_pos_div8 v | 216 syncpoint_pos_div8 v |
226 } | 217 } |
227 for(i=0; i<stream_count; i++){ | 218 for(i=0; i<stream_count; i++){ |
228 last_pts= -1 | 219 last_pts= -1 |
229 for(j=0; j<syncpoints; ){ | 220 for(j=syncpoint_start; j<syncpoints; ){ |
230 x v | 221 x v |
231 type= x & 1 | 222 type= x & 1 |
232 x>>=1 | 223 x>>=1 |
233 n=j | 224 n=j |
234 if(type){ | 225 if(type){ |
255 keyframe_pts[j][i] = last_pts + A | 246 keyframe_pts[j][i] = last_pts + A |
256 last_pts += A + B | 247 last_pts += A + B |
257 } | 248 } |
258 } | 249 } |
259 } | 250 } |
260 reserved_bytes | 251 |
261 index_ptr u(64) | 252 info_packet: |
262 checksum u(32) | |
263 | |
264 info_frame: (optional) | |
265 stream_id_plus1 v | 253 stream_id_plus1 v |
266 chapter_id v | 254 chapter_id v |
267 chapter_start v | 255 chapter_start v |
268 chapter_len v | 256 chapter_len v |
269 count v | 257 count v |
285 value.num s | 273 value.num s |
286 }else{ | 274 }else{ |
287 type= "v" | 275 type= "v" |
288 } | 276 } |
289 } | 277 } |
290 reserved_bytes | 278 |
291 checksum u(32) | 279 info_frame: |
292 | 280 info_packet |
293 info_packet: (optional) | 281 packet_footer |
294 info_startcode f(64) | |
295 forward_ptr v | |
296 info_frame | |
297 | 282 |
298 syncpoint: | 283 syncpoint: |
299 syncpoint_startcode f(64) | |
300 coded_pts v | 284 coded_pts v |
301 stream = coded_pts % stream_count | 285 stream = coded_pts % stream_count |
302 global_key_pts = coded_pts/stream_count | 286 global_key_pts = coded_pts/stream_count |
303 back_ptr_div8 v | 287 back_ptr_div8 v |
304 | 288 |
305 Complete definition: | 289 Complete definition: |
306 | 290 |
307 file: | 291 file: |
308 file_id_string | 292 file_id_string |
309 while(!eof){ | 293 while(bytes_left > 8){ |
310 main_header | 294 if(next_byte == 'N'){ |
295 startcode f(64) | |
296 forward_ptr v | |
297 switch(startcode){ | |
298 case main_startcode: main_header; break; | |
299 case stream_startcode:stream_header; break; | |
300 case info_startcode: info_packet; break; | |
301 case index_startcode: index; break; | |
302 case syncpoint_startcode: syncpoint; break; | |
303 } | |
304 reserved_bytes | |
305 checksum u(32) | |
306 }else | |
307 frame | |
308 } | |
309 index_ptr u(64) | |
310 | |
311 the structure of a undamaged file should look like the following, but | |
312 demuxers should be flexible and be able to deal with damaged headers so the | |
313 above is a better loop in practice (not to mention its simpler) | |
314 note, demuxers MUST be able to deal with new and unknown headers | |
315 | |
316 packet_header | |
317 startcode f(64) | |
318 forward_ptr v | |
319 | |
320 packet_footer | |
321 reserved_bytes | |
322 checksum u(32) | |
323 | |
324 reserved_headers | |
325 while(next_byte == 'N' && next_code != main_startcode | |
326 && next_code != stream_startcode | |
327 && next_code != info_startcode | |
328 && next_code != index_startcode | |
329 && next_code != syncpoint_startcode){ | |
330 packet_header | |
331 packet_footer | |
332 } | |
333 | |
334 file: | |
335 file_id_string | |
336 while(bytes_left > 8){ | |
337 packet_header, main_header, packet_footer | |
338 reserved_headers | |
311 for(i=0; i<stream_count; i++){ | 339 for(i=0; i<stream_count; i++){ |
312 stream_header | 340 packet_header, stream_header, packet_footer |
341 reserved_headers | |
313 } | 342 } |
314 while(next_code == info_startcode){ | 343 while(next_code == info_startcode){ |
315 info_packet | 344 packet_header, info_packet, packet_footer |
345 reserved_headers | |
316 } | 346 } |
317 if(next_code == index_startcode){ | 347 while(next_code == index_startcode){ |
318 index | 348 packet_header, index_packet, packet_footer |
349 reserved_headers | |
319 } | 350 } |
320 if (!eof) while(next_code != main_startcode){ | 351 if (bytes_left > 8) while(next_code != main_startcode){ |
321 if(next_code == syncpoint_startcode) | 352 if(next_code == syncpoint_startcode){ |
322 syncpoint | 353 packet_header, syncpoint, packet_footer |
354 } | |
323 frame | 355 frame |
356 reserved_headers | |
324 } | 357 } |
325 } | 358 } |
359 index_ptr u(64) | |
326 | 360 |
327 | 361 |
328 Tag description: | 362 Tag description: |
329 ---------------- | 363 ---------------- |
330 | 364 |
370 good reason to set it higher, otherwise reasonable error recovery will | 404 good reason to set it higher, otherwise reasonable error recovery will |
371 be impossible | 405 be impossible |
372 | 406 |
373 max_pts_distance | 407 max_pts_distance |
374 max absoloute difference of pts of new frame from last_pts in the | 408 max absoloute difference of pts of new frame from last_pts in the |
375 timebase of the stream, without a syncpoint immediately before the | 409 timebase of the stream, without a checksum after the frameheader |
376 frame. Note that last_pts is not necessarily the pts of the last frame | 410 Note that last_pts is not necessarily the pts of the last frame |
377 on the same stream, as it is altered by syncpoint timestamps. | 411 on the same stream, as it is altered by syncpoint timestamps. |
378 | 412 |
379 stream_id | 413 stream_id |
380 Stream identifier | 414 Stream identifier |
381 stream_id MUST be < stream_count | 415 stream_id MUST be < stream_count |
472 | 506 |
473 Bit Name Description | 507 Bit Name Description |
474 1 is_key if set, frame is keyframe | 508 1 is_key if set, frame is keyframe |
475 2 end_of_relevance if set, stream has no relevance on | 509 2 end_of_relevance if set, stream has no relevance on |
476 presentation. (EOR) | 510 presentation. (EOR) |
511 4 has_checksum if set then the frame header contains a checksum | |
477 | 512 |
478 EOR frames MUST be zero-length and must be set keyframe. | 513 EOR frames MUST be zero-length and must be set keyframe. |
479 All streams SHOULD end with EOR, where the pts of the EOR indicates the | 514 All streams SHOULD end with EOR, where the pts of the EOR indicates the |
480 end presentation time of the final frame. | 515 end presentation time of the final frame. |
481 An EOR set stream is unset by the first content frames. | 516 An EOR set stream is unset by the first content frames. |
482 EOR can only be unset in streams with zero decode_delay . | 517 EOR can only be unset in streams with zero decode_delay . |
518 has_checksum must be set if the frame is larger then 2*max_distance or its | |
519 pts differs by more then max_pts_distance from the last frame | |
483 | 520 |
484 stream_id_plus1[frame_code] | 521 stream_id_plus1[frame_code] |
485 must be <250 | 522 must be <250 |
486 if it is 0, then the stream_id is coded in the frame | 523 if it is 0, then the stream_id is coded in the frame |
487 | 524 |
558 checksum | 595 checksum |
559 crc32 checksum | 596 crc32 checksum |
560 checksum is calculated for the area pointed to by forward_ptr not | 597 checksum is calculated for the area pointed to by forward_ptr not |
561 including the checksum itself (from first byte after the | 598 including the checksum itself (from first byte after the |
562 forward_ptr until last byte before the checksum). | 599 forward_ptr until last byte before the checksum). |
563 In the case of info frames, covers area from begginning of frame. | 600 for frame headers the checksum contains the framecode byte and all |
601 following bytes upto the checksum itself | |
564 | 602 |
565 Syncpoint tags: | 603 Syncpoint tags: |
566 --------------- | 604 --------------- |
567 | |
568 syncpoint_checksum | |
569 crc32 checksum | |
570 checksum covers from first byte after syncpoint startcode until last | |
571 byte before the syncpoint_checksum. | |
572 | 605 |
573 back_ptr_div8 | 606 back_ptr_div8 |
574 back_ptr = back_ptr_div8 * 8 + 7 | 607 back_ptr = back_ptr_div8 * 8 + 7 |
575 back_ptr must point to a position within 8 bytes of a syncpoint | 608 back_ptr must point to a position within 8 bytes of a syncpoint |
576 startcode. This syncpoint MUST be the closest syncpoint such that at | 609 startcode. This syncpoint MUST be the closest syncpoint such that at |
610 eor_pts | 643 eor_pts |
611 Coded only if EOR is set at the position of the syncpoint. The pts of | 644 Coded only if EOR is set at the position of the syncpoint. The pts of |
612 that EOR. EOR is unset by the first keyframe after it. | 645 that EOR. EOR is unset by the first keyframe after it. |
613 | 646 |
614 index_ptr | 647 index_ptr |
615 Length in bytes of the entire index, from the first byte of the | 648 absolute location in the file of the first byte of the startcode of the |
616 startcode until the last byte of the checksum. | 649 first index packet, or 0 if there is no index |
617 Note: A demuxer can use this to find the index when it is written at | |
618 EOF, as index_ptr will always be 12 bytes before the end of file if | |
619 there is an index at all. | |
620 | 650 |
621 Info tags: | 651 Info tags: |
622 ---------- | 652 ---------- |
623 | 653 |
624 stream_id_plus1 | 654 stream_id_plus1 |
628 chapter_id | 658 chapter_id |
629 Id of chapter this packet applies to. If zero, packet applies to whole | 659 Id of chapter this packet applies to. If zero, packet applies to whole |
630 file. Positive chapter_id's are real chapters and MUST NOT overlap. | 660 file. Positive chapter_id's are real chapters and MUST NOT overlap. |
631 Negative chapter_id indicate a sub region of file and not a real | 661 Negative chapter_id indicate a sub region of file and not a real |
632 chapter. chapter_id MUST be unique to the region it represents. | 662 chapter. chapter_id MUST be unique to the region it represents. |
663 chapter_id n MUST not be used unless there are at least n chapters in the | |
664 file | |
633 | 665 |
634 chapter_start | 666 chapter_start |
635 s= chapter_start % stream_count | 667 s= chapter_start % stream_count |
636 timestamp= chapter_start / stream_count | 668 timestamp= chapter_start / stream_count |
637 timestamp of start of chapter in timebase of stream 's'. | 669 timestamp of start of chapter in timebase of stream 's'. |
722 Index: | 754 Index: |
723 ------ | 755 ------ |
724 | 756 |
725 Note: with realtime streaming, there is no end, so no index there either | 757 Note: with realtime streaming, there is no end, so no index there either |
726 Index MAY only be repeated after main headers. | 758 Index MAY only be repeated after main headers. |
727 If an index is written anywhere in the file, it MUST be written at end of | |
728 file as well. | |
729 | 759 |
730 | 760 |
731 Info: | 761 Info: |
732 ----- | 762 ----- |
733 | 763 |
740 Info frames can be used to describe the file or some part of it (chapters) | 770 Info frames can be used to describe the file or some part of it (chapters) |
741 | 771 |
742 Info SHOULD be stored in global packets instead of info streams/frames if | 772 Info SHOULD be stored in global packets instead of info streams/frames if |
743 possible, and the amount of data is not large. | 773 possible, and the amount of data is not large. |
744 | 774 |
775 If 2 info frames have the same chapter_id and stream_id then the earlier | |
776 MUST be ignored (the last info frame is the most correct, this allows | |
777 updating or correcting info) | |
778 | |
779 Info frames MUST be keyframes | |
745 | 780 |
746 demuxer (non-normative): | 781 demuxer (non-normative): |
747 ------------------------ | 782 ------------------------ |
748 | 783 |
749 in the absence of a valid header at the beginning, players SHOULD search for | 784 in the absence of a valid header at the beginning, players SHOULD search for |