|
36 | 36 |
|
37 | 37 | #include "logging.h" |
38 | 38 |
|
| 39 | +/* The size of the header buffer; should be large enough to contain |
| 40 | + * everything before the first Cluster in a reasonable stream |
| 41 | + */ |
39 | 42 | #define EBML_HEADER_MAX_SIZE 131072 |
| 43 | + |
| 44 | +/* The size of the input/staging buffers; this much of a cluster |
| 45 | + * will be buffered before being returned. Should be large enough |
| 46 | + * that the first video block will be encountered before it is full, |
| 47 | + * to allow probing for the keyframe flag while we still have the |
| 48 | + * option to mark the cluster as a sync point. |
| 49 | + */ |
40 | 50 | #define EBML_SLICE_SIZE 4096 |
41 | 51 |
|
42 | 52 | /* A value that no EBML var-int is allowed to take. */ |
|
63 | 73 | #define TRACK_TYPE_MAGIC "\x83" |
64 | 74 | #define SIMPLE_BLOCK_MAGIC "\xA3" |
65 | 75 |
|
| 76 | +/* If support for Tags gets added, it may make sense |
| 77 | + * to convert this into a pair of flags signaling |
| 78 | + * "new headers" and "new tags" |
| 79 | + */ |
66 | 80 | typedef enum ebml_read_mode { |
| 81 | + /* The header buffer has not been extracted yet */ |
67 | 82 | EBML_STATE_READING_HEADER = 0, |
| 83 | + /* The header buffer has been read, begin normal operation */ |
68 | 84 | EBML_STATE_READING_CLUSTERS |
69 | 85 | } ebml_read_mode; |
70 | 86 |
|
71 | 87 | typedef enum ebml_parsing_state { |
| 88 | + /* Examine EBML elements, output to header buffer */ |
72 | 89 | EBML_STATE_PARSING_HEADER = 0, |
| 90 | + |
| 91 | + /* Blindly copy a specified number of bytes to the header buffer */ |
73 | 92 | EBML_STATE_COPYING_TO_HEADER, |
| 93 | + |
| 94 | + /* Finalize header buffer and wait for previous cluster to flush (as necessary) */ |
74 | 95 | EBML_STATE_START_CLUSTER, |
| 96 | + |
| 97 | + /* Examine EBML elements, output to data buffer */ |
75 | 98 | EBML_STATE_PARSING_CLUSTERS, |
| 99 | + |
| 100 | + /* Blindly copy a specified number of bytes to the data buffer */ |
76 | 101 | EBML_STATE_COPYING_TO_DATA |
77 | 102 | } ebml_parsing_state; |
78 | 103 |
|
79 | 104 | typedef enum ebml_chunk_type { |
| 105 | + /* This chunk is the header buffer */ |
80 | 106 | EBML_CHUNK_HEADER = 0, |
| 107 | + |
| 108 | + /* This chunk starts a cluster that works as a sync point */ |
81 | 109 | EBML_CHUNK_CLUSTER_START, |
| 110 | + |
| 111 | + /* This chunk continues the previous cluster, or |
| 112 | + * else starts a non-sync-point cluster |
| 113 | + */ |
82 | 114 | EBML_CHUNK_CLUSTER_CONTINUE |
83 | 115 | } ebml_chunk_type; |
84 | 116 |
|
85 | 117 | typedef enum ebml_keyframe_status { |
| 118 | + /* Have not found a video track block yet */ |
86 | 119 | EBML_KEYFRAME_UNKNOWN = -1, |
| 120 | + |
| 121 | + /* Found the first video track block, it was not a keyframe */ |
87 | 122 | EBML_KEYFRAME_DOES_NOT_START_CLUSTER = 0, |
| 123 | + |
| 124 | + /* Found the first video track block, it was a keyframe */ |
88 | 125 | EBML_KEYFRAME_STARTS_CLUSTER = 1 |
89 | 126 | } ebml_keyframe_status; |
90 | 127 |
|
@@ -695,9 +732,8 @@ static int ebml_wrote(ebml_t *ebml, int len) |
695 | 732 | } |
696 | 733 | } |
697 | 734 |
|
698 | | - /* Copy any data we don't need to probe any more */ |
699 | 735 | if (processing) { |
700 | | - /* Non-cluster tag, copy it & children into buffer */ |
| 736 | + /* Moving to next element, copy current to buffer */ |
701 | 737 | ebml->copy_len = tag_length + payload_length; |
702 | 738 | ebml->parse_state = copy_state; |
703 | 739 | } |
|
0 commit comments