1
0

Tracks.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. #pragma once
  2. #include <bfc/platform/types.h>
  3. #include "mkv_reader.h"
  4. #include <vector>
  5. const uint32_t mkv_segment_tracks = 0x654ae6b;
  6. const uint32_t mkv_tracks_trackentry = 0x2e;
  7. const uint32_t mkv_tracks_tracknumber=0x57;
  8. const uint32_t mkv_tracks_trackuid=0x33c5;
  9. const uint32_t mkv_tracks_tracktype=0x3;
  10. const uint32_t mkv_tracks_flagenabled=0x39;
  11. const uint32_t mkv_tracks_flagdefault=0x8;
  12. const uint32_t mkv_tracks_flagforced=0x15aa;
  13. const uint32_t mkv_tracks_flaglacing=0x1c;
  14. const uint32_t mkv_tracks_mincache=0x2de7;
  15. const uint32_t mkv_tracks_tracktimecodescale=0x3314f;
  16. const uint32_t mkv_tracks_maxblockadditionid=0x15ee;
  17. const uint32_t mkv_tracks_codecid=0x6;
  18. const uint32_t mkv_tracks_codecdecodeall=0x2A;
  19. const uint32_t mkv_tracks_defaultduration=0x3e383;
  20. const uint32_t mkv_tracks_codecprivate=0x23a2;
  21. const uint32_t mkv_tracks_language=0x2b59c;
  22. const uint32_t mkv_tracks_name=0x136e;
  23. const uint32_t mkv_tracks_maxcache=0x2df8;
  24. // Track - video settings
  25. const uint32_t mkv_tracks_video=0x60;
  26. const uint32_t mkv_video_pixelwidth = 0x30;
  27. const uint32_t mkv_video_pixelheight = 0x3a;
  28. const uint32_t mkv_video_flaginterlaced = 0x1a;
  29. const uint32_t mkv_video_displaywidth = 0x14b0;
  30. const uint32_t mkv_video_displayheight = 0x14ba;
  31. const uint32_t mkv_video_pixelcropbottom = 0x14aa;
  32. const uint32_t mkv_video_pixelcroptop = 0x14bb;
  33. const uint32_t mkv_video_pixelcropleft = 0x14cc;
  34. const uint32_t mkv_video_pixelcropright = 0x14dd;
  35. // Track - audio settings;
  36. const uint32_t mkv_tracks_audio=0x61;
  37. const uint32_t mkv_audio_samplingfrequency=0x35;
  38. const uint32_t mkv_audio_channels = 0x1f;
  39. const uint32_t mkv_audio_output_samplingfrequency=0x38b5;
  40. // Track Types
  41. enum
  42. {
  43. mkv_track_type_video = 0x01,
  44. mkv_track_type_audio = 0x02,
  45. mkv_track_type_complex = 0x03, // i.e., combined video and audio
  46. mkv_track_type_logo = 0x10,
  47. mkv_track_type_subtitle = 0x11,
  48. mkv_track_type_buttons = 0x12,
  49. mkv_track_type_control = 0x20,
  50. };
  51. /* TODO: benski>
  52. */
  53. namespace nsmkv
  54. {
  55. #pragma pack(push, 8)
  56. struct VideoData
  57. {
  58. size_t struct_size;
  59. uint64_t pixel_width;
  60. uint64_t pixel_height;
  61. uint64_t pixel_crop_bottom;
  62. uint64_t pixel_crop_top;
  63. uint64_t pixel_crop_left;
  64. uint64_t pixel_crop_right;
  65. uint64_t display_width;
  66. uint64_t display_height;
  67. uint64_t display_unit;
  68. bool flag_interlaced;
  69. };
  70. #pragma pack(pop)
  71. class Video : public VideoData
  72. {
  73. public:
  74. Video()
  75. #ifdef WA_VALIDATE
  76. :
  77. pixel_width_found(false),
  78. pixel_height_found(false),
  79. pixel_crop_bottom_found(false),
  80. pixel_crop_top_found(false),
  81. pixel_crop_left_found(false),
  82. pixel_crop_right_found(false),
  83. display_width_found(false),
  84. display_height_found(false),
  85. // display_unit_found(false),
  86. flag_interlaced_found(false)
  87. #endif
  88. {
  89. struct_size = sizeof(VideoData);
  90. pixel_width=0;
  91. pixel_height=0;
  92. pixel_crop_bottom=0;
  93. pixel_crop_top=0;
  94. pixel_crop_left=0;
  95. pixel_crop_right=0;
  96. display_width=0;
  97. display_height=0;
  98. display_unit=0;
  99. flag_interlaced=false;
  100. }
  101. #ifdef WA_VALIDATE
  102. bool pixel_width_found;
  103. bool pixel_height_found;
  104. bool pixel_crop_bottom_found;
  105. bool pixel_crop_top_found;
  106. bool pixel_crop_left_found;
  107. bool pixel_crop_right_found;
  108. bool display_width_found;
  109. bool display_height_found;
  110. // bool display_unit_found;
  111. bool flag_interlaced_found;
  112. #endif
  113. };
  114. #pragma pack(push, 8)
  115. struct AudioData
  116. {
  117. size_t struct_size;
  118. uint64_t sampling_frequency;
  119. uint64_t channels;
  120. uint64_t bit_depth;
  121. uint64_t output_sampling_frequency;
  122. };
  123. #pragma pack(pop)
  124. class Audio : public AudioData
  125. {
  126. public:
  127. Audio()
  128. #ifdef WA_VALIDATE
  129. :
  130. sampling_frequency_found(false),
  131. channels_found(false),
  132. // bit_depth_found(false),
  133. output_sampling_frequency_found(false)
  134. #endif
  135. {
  136. struct_size = sizeof(AudioData);
  137. sampling_frequency=8000;
  138. channels=1;
  139. bit_depth=0;
  140. output_sampling_frequency=0;
  141. }
  142. #ifdef WA_VALIDATE
  143. bool sampling_frequency_found;
  144. bool channels_found;
  145. // bool bit_depth_found;
  146. bool output_sampling_frequency_found;
  147. #endif
  148. };
  149. #pragma pack(push, 8)
  150. struct TrackEntryData
  151. {
  152. size_t struct_size;
  153. uint64_t track_number;
  154. uint64_t track_uid;
  155. uint64_t track_type;
  156. bool flag_enabled;
  157. bool flag_default;
  158. bool flag_forced;
  159. bool flag_lacing;
  160. bool decode_all;
  161. uint64_t min_cache;
  162. uint64_t max_cache;
  163. uint64_t default_duration;
  164. double track_timecode_scale;
  165. uint64_t max_block_additional_id;
  166. char *name;
  167. char *language;
  168. char *codec_id;
  169. void *codec_private;
  170. size_t codec_private_len;
  171. char *codec_name;
  172. uint64_t attachment_link;
  173. };
  174. #pragma pack(pop)
  175. class TrackEntry : public TrackEntryData
  176. {
  177. public:
  178. TrackEntry()
  179. #ifdef WA_VALIDATE
  180. :
  181. track_number_found(false),
  182. track_uid_found(false),
  183. track_type_found(false),
  184. flag_enabled_found(false),
  185. flag_default_found(false),
  186. flag_forced_found(false),
  187. flag_lacing_found(false),
  188. min_cache_found(false),
  189. max_cache_found(false),
  190. default_duration_found(false),
  191. track_timecode_scale_found(false),
  192. max_block_additional_id_found(false),
  193. decode_all_found(false),
  194. name_found(false),
  195. language_found(false),
  196. codec_id_found(false),
  197. codec_private_found(false),
  198. codec_name_found(false)
  199. // attachment_link_found(false)
  200. #endif
  201. {
  202. struct_size = sizeof(TrackEntryData);
  203. track_number = 0;
  204. track_uid = 0;
  205. track_type = 0;
  206. flag_enabled = true;
  207. flag_default = true;
  208. flag_forced = false;
  209. flag_lacing = false;
  210. min_cache = 0;
  211. max_cache = 0;
  212. default_duration = 0;
  213. track_timecode_scale = 0;
  214. max_block_additional_id = 0;
  215. decode_all = true;
  216. name = 0;
  217. language = 0;
  218. codec_id = 0;
  219. codec_private = 0;
  220. codec_private_len = 0;
  221. codec_name = 0;
  222. attachment_link = 0;
  223. }
  224. ~TrackEntry()
  225. {
  226. free(name);
  227. free(language);
  228. free(codec_id);
  229. free(codec_private);
  230. free(codec_name);
  231. }
  232. void Own(char *&field, char *value)
  233. {
  234. if (field)
  235. free(field);
  236. field = value;
  237. }
  238. void OwnCodecPrivate(void *_codec_private, size_t _codec_private_len)
  239. {
  240. free(codec_private);
  241. codec_private=_codec_private;
  242. codec_private_len = _codec_private_len;
  243. }
  244. Video video;
  245. Audio audio;
  246. #ifdef WA_VALIDATE
  247. bool track_number_found;
  248. bool track_uid_found;
  249. bool track_type_found;
  250. bool flag_enabled_found;
  251. bool flag_default_found;
  252. bool flag_forced_found;
  253. bool flag_lacing_found;
  254. bool min_cache_found;
  255. bool max_cache_found;
  256. bool default_duration_found;
  257. bool track_timecode_scale_found;
  258. bool max_block_additional_id_found;
  259. bool decode_all_found;
  260. bool name_found;
  261. bool language_found;
  262. bool codec_id_found;
  263. bool codec_private_found;
  264. bool codec_name_found;
  265. // bool attachment_link_found;
  266. #endif
  267. };
  268. class Tracks
  269. {
  270. public:
  271. ~Tracks()
  272. {
  273. //tracks.deleteAll();
  274. for (auto obj : tracks)
  275. {
  276. delete obj;
  277. }
  278. tracks.clear();
  279. }
  280. const nsmkv::TrackEntry *EnumTrack(size_t i) const;
  281. typedef std::vector<nsmkv::TrackEntry*> TrackEntryList;
  282. TrackEntryList tracks;
  283. };
  284. uint64_t ReadTracks(nsmkv::MKVReader *reader, uint64_t size, nsmkv::Tracks &tracks);
  285. }