| OLD | NEW |
| 1 // Copyright (c) 2012 The WebM project authors. All Rights Reserved. | 1 // Copyright (c) 2012 The WebM project authors. All Rights Reserved. |
| 2 // | 2 // |
| 3 // Use of this source code is governed by a BSD-style license | 3 // Use of this source code is governed by a BSD-style license |
| 4 // that can be found in the LICENSE file in the root of the source | 4 // that can be found in the LICENSE file in the root of the source |
| 5 // tree. An additional intellectual property rights grant can be found | 5 // tree. An additional intellectual property rights grant can be found |
| 6 // in the file PATENTS. All contributing project authors may | 6 // in the file PATENTS. All contributing project authors may |
| 7 // be found in the AUTHORS file in the root of the source tree. | 7 // be found in the AUTHORS file in the root of the source tree. |
| 8 | 8 |
| 9 #ifndef MKVMUXER_HPP | 9 #ifndef MKVMUXER_HPP |
| 10 #define MKVMUXER_HPP | 10 #define MKVMUXER_HPP |
| 11 | 11 |
| 12 #include "mkvmuxertypes.hpp" | 12 #include "mkvmuxertypes.hpp" |
| 13 | 13 |
| 14 // For a description of the WebM elements see | 14 // For a description of the WebM elements see |
| 15 // http://www.webmproject.org/code/specs/container/. | 15 // http://www.webmproject.org/code/specs/container/. |
| 16 | 16 |
| 17 namespace mkvparser { | 17 namespace mkvparser { |
| 18 class IMkvReader; | 18 class IMkvReader; |
| 19 } // end namespace | 19 } // end namespace |
| 20 | 20 |
| 21 namespace mkvmuxer { | 21 namespace mkvmuxer { |
| 22 | 22 |
| 23 class MkvWriter; | 23 class MkvWriter; |
| 24 class Segment; | 24 class Segment; |
| 25 | 25 |
| 26 const uint64 kMaxTrackNumber = 126; |
| 27 |
| 26 /////////////////////////////////////////////////////////////// | 28 /////////////////////////////////////////////////////////////// |
| 27 // Interface used by the mkvmuxer to write out the Mkv data. | 29 // Interface used by the mkvmuxer to write out the Mkv data. |
| 28 class IMkvWriter { | 30 class IMkvWriter { |
| 29 public: | 31 public: |
| 30 // Writes out |len| bytes of |buf|. Returns 0 on success. | 32 // Writes out |len| bytes of |buf|. Returns 0 on success. |
| 31 virtual int32 Write(const void* buf, uint32 len) = 0; | 33 virtual int32 Write(const void* buf, uint32 len) = 0; |
| 32 | 34 |
| 33 // Returns the offset of the output position from the beginning of the | 35 // Returns the offset of the output position from the beginning of the |
| 34 // output. | 36 // output. |
| 35 virtual int64 Position() const = 0; | 37 virtual int64 Position() const = 0; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 50 protected: | 52 protected: |
| 51 IMkvWriter(); | 53 IMkvWriter(); |
| 52 virtual ~IMkvWriter(); | 54 virtual ~IMkvWriter(); |
| 53 | 55 |
| 54 private: | 56 private: |
| 55 LIBWEBM_DISALLOW_COPY_AND_ASSIGN(IMkvWriter); | 57 LIBWEBM_DISALLOW_COPY_AND_ASSIGN(IMkvWriter); |
| 56 }; | 58 }; |
| 57 | 59 |
| 58 // Writes out the EBML header for a WebM file. This function must be called | 60 // Writes out the EBML header for a WebM file. This function must be called |
| 59 // before any other libwebm writing functions are called. | 61 // before any other libwebm writing functions are called. |
| 62 bool WriteEbmlHeader(IMkvWriter* writer, uint64 doc_type_version); |
| 63 |
| 64 // Deprecated. Writes out EBML header with doc_type_version as |
| 65 // kDefaultDocTypeVersion. Exists for backward compatibility. |
| 60 bool WriteEbmlHeader(IMkvWriter* writer); | 66 bool WriteEbmlHeader(IMkvWriter* writer); |
| 61 | 67 |
| 62 // Copies in Chunk from source to destination between the given byte positions | 68 // Copies in Chunk from source to destination between the given byte positions |
| 63 bool ChunkedCopy(mkvparser::IMkvReader* source, IMkvWriter* dst, int64 start, | 69 bool ChunkedCopy(mkvparser::IMkvReader* source, IMkvWriter* dst, int64 start, |
| 64 int64 size); | 70 int64 size); |
| 65 | 71 |
| 66 /////////////////////////////////////////////////////////////// | 72 /////////////////////////////////////////////////////////////// |
| 67 // Class to hold data the will be written to a block. | 73 // Class to hold data the will be written to a block. |
| 68 class Frame { | 74 class Frame { |
| 69 public: | 75 public: |
| 70 Frame(); | 76 Frame(); |
| 71 ~Frame(); | 77 ~Frame(); |
| 72 | 78 |
| 79 // Sets this frame's contents based on |frame|. Returns true on success. On |
| 80 // failure, this frame's existing contents may be lost. |
| 81 bool CopyFrom(const Frame& frame); |
| 82 |
| 73 // Copies |frame| data into |frame_|. Returns true on success. | 83 // Copies |frame| data into |frame_|. Returns true on success. |
| 74 bool Init(const uint8* frame, uint64 length); | 84 bool Init(const uint8* frame, uint64 length); |
| 75 | 85 |
| 76 // Copies |additional| data into |additional_|. Returns true on success. | 86 // Copies |additional| data into |additional_|. Returns true on success. |
| 77 bool AddAdditionalData(const uint8* additional, uint64 length, uint64 add_id); | 87 bool AddAdditionalData(const uint8* additional, uint64 length, uint64 add_id); |
| 78 | 88 |
| 89 // Returns true if the frame has valid parameters. |
| 90 bool IsValid() const; |
| 91 |
| 92 // Returns true if the frame can be written as a SimpleBlock based on current |
| 93 // parameters. |
| 94 bool CanBeSimpleBlock() const; |
| 95 |
| 79 uint64 add_id() const { return add_id_; } | 96 uint64 add_id() const { return add_id_; } |
| 80 const uint8* additional() const { return additional_; } | 97 const uint8* additional() const { return additional_; } |
| 81 uint64 additional_length() const { return additional_length_; } | 98 uint64 additional_length() const { return additional_length_; } |
| 82 void set_duration(uint64 duration) { duration_ = duration; } | 99 void set_duration(uint64 duration) { duration_ = duration; } |
| 83 uint64 duration() const { return duration_; } | 100 uint64 duration() const { return duration_; } |
| 84 const uint8* frame() const { return frame_; } | 101 const uint8* frame() const { return frame_; } |
| 85 void set_is_key(bool key) { is_key_ = key; } | 102 void set_is_key(bool key) { is_key_ = key; } |
| 86 bool is_key() const { return is_key_; } | 103 bool is_key() const { return is_key_; } |
| 87 uint64 length() const { return length_; } | 104 uint64 length() const { return length_; } |
| 88 void set_track_number(uint64 track_number) { track_number_ = track_number; } | 105 void set_track_number(uint64 track_number) { track_number_ = track_number; } |
| 89 uint64 track_number() const { return track_number_; } | 106 uint64 track_number() const { return track_number_; } |
| 90 void set_timestamp(uint64 timestamp) { timestamp_ = timestamp; } | 107 void set_timestamp(uint64 timestamp) { timestamp_ = timestamp; } |
| 91 uint64 timestamp() const { return timestamp_; } | 108 uint64 timestamp() const { return timestamp_; } |
| 92 void set_discard_padding(uint64 discard_padding) { | 109 void set_discard_padding(int64 discard_padding) { |
| 93 discard_padding_ = discard_padding; | 110 discard_padding_ = discard_padding; |
| 94 } | 111 } |
| 95 uint64 discard_padding() const { return discard_padding_; } | 112 int64 discard_padding() const { return discard_padding_; } |
| 113 void set_reference_block_timestamp(int64 reference_block_timestamp); |
| 114 int64 reference_block_timestamp() const { return reference_block_timestamp_; } |
| 115 bool reference_block_timestamp_set() const { |
| 116 return reference_block_timestamp_set_; |
| 117 } |
| 96 | 118 |
| 97 private: | 119 private: |
| 98 // Id of the Additional data. | 120 // Id of the Additional data. |
| 99 uint64 add_id_; | 121 uint64 add_id_; |
| 100 | 122 |
| 101 // Pointer to additional data. Owned by this class. | 123 // Pointer to additional data. Owned by this class. |
| 102 uint8* additional_; | 124 uint8* additional_; |
| 103 | 125 |
| 104 // Length of the additional data. | 126 // Length of the additional data. |
| 105 uint64 additional_length_; | 127 uint64 additional_length_; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 117 uint64 length_; | 139 uint64 length_; |
| 118 | 140 |
| 119 // Mkv track number the data is associated with. | 141 // Mkv track number the data is associated with. |
| 120 uint64 track_number_; | 142 uint64 track_number_; |
| 121 | 143 |
| 122 // Timestamp of the data in nanoseconds. | 144 // Timestamp of the data in nanoseconds. |
| 123 uint64 timestamp_; | 145 uint64 timestamp_; |
| 124 | 146 |
| 125 // Discard padding for the frame. | 147 // Discard padding for the frame. |
| 126 int64 discard_padding_; | 148 int64 discard_padding_; |
| 149 |
| 150 // Reference block timestamp. |
| 151 int64 reference_block_timestamp_; |
| 152 |
| 153 // Flag indicating if |reference_block_timestamp_| has been set. |
| 154 bool reference_block_timestamp_set_; |
| 155 |
| 156 LIBWEBM_DISALLOW_COPY_AND_ASSIGN(Frame); |
| 127 }; | 157 }; |
| 128 | 158 |
| 129 /////////////////////////////////////////////////////////////// | 159 /////////////////////////////////////////////////////////////// |
| 130 // Class to hold one cue point in a Cues element. | 160 // Class to hold one cue point in a Cues element. |
| 131 class CuePoint { | 161 class CuePoint { |
| 132 public: | 162 public: |
| 133 CuePoint(); | 163 CuePoint(); |
| 134 ~CuePoint(); | 164 ~CuePoint(); |
| 135 | 165 |
| 136 // Returns the size in bytes for the entire CuePoint element. | 166 // Returns the size in bytes for the entire CuePoint element. |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 // Sets the video's stereo mode. Returns true on success. | 445 // Sets the video's stereo mode. Returns true on success. |
| 416 bool SetStereoMode(uint64 stereo_mode); | 446 bool SetStereoMode(uint64 stereo_mode); |
| 417 | 447 |
| 418 // Sets the video's alpha mode. Returns true on success. | 448 // Sets the video's alpha mode. Returns true on success. |
| 419 bool SetAlphaMode(uint64 alpha_mode); | 449 bool SetAlphaMode(uint64 alpha_mode); |
| 420 | 450 |
| 421 void set_display_height(uint64 height) { display_height_ = height; } | 451 void set_display_height(uint64 height) { display_height_ = height; } |
| 422 uint64 display_height() const { return display_height_; } | 452 uint64 display_height() const { return display_height_; } |
| 423 void set_display_width(uint64 width) { display_width_ = width; } | 453 void set_display_width(uint64 width) { display_width_ = width; } |
| 424 uint64 display_width() const { return display_width_; } | 454 uint64 display_width() const { return display_width_; } |
| 455 |
| 456 void set_crop_left(uint64 crop_left) { crop_left_ = crop_left; } |
| 457 uint64 crop_left() const { return crop_left_; } |
| 458 void set_crop_right(uint64 crop_right) { crop_right_ = crop_right; } |
| 459 uint64 crop_right() const { return crop_right_; } |
| 460 void set_crop_top(uint64 crop_top) { crop_top_ = crop_top; } |
| 461 uint64 crop_top() const { return crop_top_; } |
| 462 void set_crop_bottom(uint64 crop_bottom) { crop_bottom_ = crop_bottom; } |
| 463 uint64 crop_bottom() const { return crop_bottom_; } |
| 464 |
| 425 void set_frame_rate(double frame_rate) { frame_rate_ = frame_rate; } | 465 void set_frame_rate(double frame_rate) { frame_rate_ = frame_rate; } |
| 426 double frame_rate() const { return frame_rate_; } | 466 double frame_rate() const { return frame_rate_; } |
| 427 void set_height(uint64 height) { height_ = height; } | 467 void set_height(uint64 height) { height_ = height; } |
| 428 uint64 height() const { return height_; } | 468 uint64 height() const { return height_; } |
| 429 uint64 stereo_mode() { return stereo_mode_; } | 469 uint64 stereo_mode() { return stereo_mode_; } |
| 430 uint64 alpha_mode() { return alpha_mode_; } | 470 uint64 alpha_mode() { return alpha_mode_; } |
| 431 void set_width(uint64 width) { width_ = width; } | 471 void set_width(uint64 width) { width_ = width; } |
| 432 uint64 width() const { return width_; } | 472 uint64 width() const { return width_; } |
| 433 | 473 |
| 434 private: | 474 private: |
| 435 // Returns the size in bytes of the Video element. | 475 // Returns the size in bytes of the Video element. |
| 436 uint64 VideoPayloadSize() const; | 476 uint64 VideoPayloadSize() const; |
| 437 | 477 |
| 438 // Video track element names. | 478 // Video track element names. |
| 439 uint64 display_height_; | 479 uint64 display_height_; |
| 440 uint64 display_width_; | 480 uint64 display_width_; |
| 481 uint64 crop_left_; |
| 482 uint64 crop_right_; |
| 483 uint64 crop_top_; |
| 484 uint64 crop_bottom_; |
| 441 double frame_rate_; | 485 double frame_rate_; |
| 442 uint64 height_; | 486 uint64 height_; |
| 443 uint64 stereo_mode_; | 487 uint64 stereo_mode_; |
| 444 uint64 alpha_mode_; | 488 uint64 alpha_mode_; |
| 445 uint64 width_; | 489 uint64 width_; |
| 446 | 490 |
| 447 LIBWEBM_DISALLOW_COPY_AND_ASSIGN(VideoTrack); | 491 LIBWEBM_DISALLOW_COPY_AND_ASSIGN(VideoTrack); |
| 448 }; | 492 }; |
| 449 | 493 |
| 450 /////////////////////////////////////////////////////////////// | 494 /////////////////////////////////////////////////////////////// |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 // Tracks element | 526 // Tracks element |
| 483 class Tracks { | 527 class Tracks { |
| 484 public: | 528 public: |
| 485 // Audio and video type defined by the Matroska specs. | 529 // Audio and video type defined by the Matroska specs. |
| 486 enum { kVideo = 0x1, kAudio = 0x2 }; | 530 enum { kVideo = 0x1, kAudio = 0x2 }; |
| 487 // Opus, Vorbis, VP8, and VP9 codec ids defined by the Matroska specs. | 531 // Opus, Vorbis, VP8, and VP9 codec ids defined by the Matroska specs. |
| 488 static const char kOpusCodecId[]; | 532 static const char kOpusCodecId[]; |
| 489 static const char kVorbisCodecId[]; | 533 static const char kVorbisCodecId[]; |
| 490 static const char kVp8CodecId[]; | 534 static const char kVp8CodecId[]; |
| 491 static const char kVp9CodecId[]; | 535 static const char kVp9CodecId[]; |
| 536 static const char kVp10CodecId[]; |
| 492 | 537 |
| 493 Tracks(); | 538 Tracks(); |
| 494 ~Tracks(); | 539 ~Tracks(); |
| 495 | 540 |
| 496 // Adds a Track element to the Tracks object. |track| will be owned and | 541 // Adds a Track element to the Tracks object. |track| will be owned and |
| 497 // deleted by the Tracks object. Returns true on success. |number| is the | 542 // deleted by the Tracks object. Returns true on success. |number| is the |
| 498 // number to use for the track. |number| must be >= 0. If |number| == 0 | 543 // number to use for the track. |number| must be >= 0. If |number| == 0 |
| 499 // then the muxer will decide on the track number. | 544 // then the muxer will decide on the track number. |
| 500 bool AddTrack(Track* track, int32 number); | 545 bool AddTrack(Track* track, int32 number); |
| 501 | 546 |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 686 // Number of active chapters on the chapters_ array. | 731 // Number of active chapters on the chapters_ array. |
| 687 int chapters_count_; | 732 int chapters_count_; |
| 688 | 733 |
| 689 // Array for storage of chapter objects. | 734 // Array for storage of chapter objects. |
| 690 Chapter* chapters_; | 735 Chapter* chapters_; |
| 691 | 736 |
| 692 LIBWEBM_DISALLOW_COPY_AND_ASSIGN(Chapters); | 737 LIBWEBM_DISALLOW_COPY_AND_ASSIGN(Chapters); |
| 693 }; | 738 }; |
| 694 | 739 |
| 695 /////////////////////////////////////////////////////////////// | 740 /////////////////////////////////////////////////////////////// |
| 741 // Tag element |
| 742 // |
| 743 class Tag { |
| 744 public: |
| 745 bool add_simple_tag(const char* tag_name, const char* tag_string); |
| 746 |
| 747 private: |
| 748 // Tags calls Clear and the destructor of Tag |
| 749 friend class Tags; |
| 750 |
| 751 // For storage of simple tags |
| 752 class SimpleTag { |
| 753 public: |
| 754 // Establish representation invariant for new SimpleTag object. |
| 755 void Init(); |
| 756 |
| 757 // Reclaim resources, in anticipation of destruction. |
| 758 void Clear(); |
| 759 |
| 760 // Copies the title to the |tag_name_| member. Returns false on |
| 761 // error. |
| 762 bool set_tag_name(const char* tag_name); |
| 763 |
| 764 // Copies the language to the |tag_string_| member. Returns false |
| 765 // on error. |
| 766 bool set_tag_string(const char* tag_string); |
| 767 |
| 768 // If |writer| is non-NULL, serialize the SimpleTag sub-element of |
| 769 // the Atom into the stream. Returns the SimpleTag element size on |
| 770 // success, 0 if error. |
| 771 uint64 Write(IMkvWriter* writer) const; |
| 772 |
| 773 private: |
| 774 char* tag_name_; |
| 775 char* tag_string_; |
| 776 }; |
| 777 |
| 778 Tag(); |
| 779 ~Tag(); |
| 780 |
| 781 // Copies this Tag object to a different one. This is used when |
| 782 // expanding a plain array of Tag objects (see Tags). |
| 783 void ShallowCopy(Tag* dst) const; |
| 784 |
| 785 // Reclaim resources used by this Tag object, pending its |
| 786 // destruction. |
| 787 void Clear(); |
| 788 |
| 789 // If there is no storage remaining on the |simple_tags_| array for a |
| 790 // new display object, creates a new, longer array and copies the |
| 791 // existing SimpleTag objects to the new array. Returns false if the |
| 792 // array cannot be expanded. |
| 793 bool ExpandSimpleTagsArray(); |
| 794 |
| 795 // If |writer| is non-NULL, serialize the Tag sub-element into the |
| 796 // stream. Returns the total size of the element on success, 0 if |
| 797 // error. |
| 798 uint64 Write(IMkvWriter* writer) const; |
| 799 |
| 800 // The Atom element can contain multiple SimpleTag sub-elements |
| 801 SimpleTag* simple_tags_; |
| 802 |
| 803 // The physical length (total size) of the |simple_tags_| array. |
| 804 int simple_tags_size_; |
| 805 |
| 806 // The logical length (number of active elements) on the |simple_tags_| |
| 807 // array. |
| 808 int simple_tags_count_; |
| 809 |
| 810 LIBWEBM_DISALLOW_COPY_AND_ASSIGN(Tag); |
| 811 }; |
| 812 |
| 813 /////////////////////////////////////////////////////////////// |
| 814 // Tags element |
| 815 // |
| 816 class Tags { |
| 817 public: |
| 818 Tags(); |
| 819 ~Tags(); |
| 820 |
| 821 Tag* AddTag(); |
| 822 |
| 823 // Returns the number of tags that have been added. |
| 824 int Count() const; |
| 825 |
| 826 // Output the Tags element to the writer. Returns true on success. |
| 827 bool Write(IMkvWriter* writer) const; |
| 828 |
| 829 private: |
| 830 // Expands the tags_ array if there is not enough space to contain |
| 831 // another tag object. Returns true on success. |
| 832 bool ExpandTagsArray(); |
| 833 |
| 834 // Total length of the tags_ array. |
| 835 int tags_size_; |
| 836 |
| 837 // Number of active tags on the tags_ array. |
| 838 int tags_count_; |
| 839 |
| 840 // Array for storage of tag objects. |
| 841 Tag* tags_; |
| 842 |
| 843 LIBWEBM_DISALLOW_COPY_AND_ASSIGN(Tags); |
| 844 }; |
| 845 |
| 846 /////////////////////////////////////////////////////////////// |
| 696 // Cluster element | 847 // Cluster element |
| 697 // | 848 // |
| 698 // Notes: | 849 // Notes: |
| 699 // |Init| must be called before any other method in this class. | 850 // |Init| must be called before any other method in this class. |
| 700 class Cluster { | 851 class Cluster { |
| 701 public: | 852 public: |
| 702 Cluster(uint64 timecode, int64 cues_pos); | 853 // |timecode| is the absolute timecode of the cluster. |cues_pos| is the |
| 854 // position for the cluster within the segment that should be written in |
| 855 // the cues element. |timecode_scale| is the timecode scale of the segment. |
| 856 Cluster(uint64 timecode, int64 cues_pos, uint64 timecode_scale); |
| 703 ~Cluster(); | 857 ~Cluster(); |
| 704 | 858 |
| 705 // |timecode| is the absolute timecode of the cluster. |cues_pos| is the | |
| 706 // position for the cluster within the segment that should be written in | |
| 707 // the cues element. | |
| 708 bool Init(IMkvWriter* ptr_writer); | 859 bool Init(IMkvWriter* ptr_writer); |
| 709 | 860 |
| 710 // Adds a frame to be output in the file. The frame is written out through | 861 // Adds a frame to be output in the file. The frame is written out through |
| 711 // |writer_| if successful. Returns true on success. | 862 // |writer_| if successful. Returns true on success. |
| 863 bool AddFrame(const Frame* frame); |
| 864 |
| 865 // Adds a frame to be output in the file. The frame is written out through |
| 866 // |writer_| if successful. Returns true on success. |
| 712 // Inputs: | 867 // Inputs: |
| 713 // frame: Pointer to the data | 868 // data: Pointer to the data |
| 714 // length: Length of the data | 869 // length: Length of the data |
| 715 // track_number: Track to add the data to. Value returned by Add track | 870 // track_number: Track to add the data to. Value returned by Add track |
| 716 // functions. The range of allowed values is [1, 126]. | 871 // functions. The range of allowed values is [1, 126]. |
| 717 // timecode: Absolute (not relative to cluster) timestamp of the | 872 // timecode: Absolute (not relative to cluster) timestamp of the |
| 718 // frame, expressed in timecode units. | 873 // frame, expressed in timecode units. |
| 719 // is_key: Flag telling whether or not this frame is a key frame. | 874 // is_key: Flag telling whether or not this frame is a key frame. |
| 720 bool AddFrame(const uint8* frame, uint64 length, uint64 track_number, | 875 bool AddFrame(const uint8* data, uint64 length, uint64 track_number, |
| 721 uint64 timecode, // timecode units (absolute) | 876 uint64 timecode, // timecode units (absolute) |
| 722 bool is_key); | 877 bool is_key); |
| 723 | 878 |
| 724 // Adds a frame to be output in the file. The frame is written out through | 879 // Adds a frame to be output in the file. The frame is written out through |
| 725 // |writer_| if successful. Returns true on success. | 880 // |writer_| if successful. Returns true on success. |
| 726 // Inputs: | 881 // Inputs: |
| 727 // frame: Pointer to the data | 882 // data: Pointer to the data |
| 728 // length: Length of the data | 883 // length: Length of the data |
| 729 // additional: Pointer to the additional data | 884 // additional: Pointer to the additional data |
| 730 // additional_length: Length of the additional data | 885 // additional_length: Length of the additional data |
| 731 // add_id: Value of BlockAddID element | 886 // add_id: Value of BlockAddID element |
| 732 // track_number: Track to add the data to. Value returned by Add track | 887 // track_number: Track to add the data to. Value returned by Add track |
| 733 // functions. The range of allowed values is [1, 126]. | 888 // functions. The range of allowed values is [1, 126]. |
| 734 // abs_timecode: Absolute (not relative to cluster) timestamp of the | 889 // abs_timecode: Absolute (not relative to cluster) timestamp of the |
| 735 // frame, expressed in timecode units. | 890 // frame, expressed in timecode units. |
| 736 // is_key: Flag telling whether or not this frame is a key frame. | 891 // is_key: Flag telling whether or not this frame is a key frame. |
| 737 bool AddFrameWithAdditional(const uint8* frame, uint64 length, | 892 bool AddFrameWithAdditional(const uint8* data, uint64 length, |
| 738 const uint8* additional, uint64 additional_length, | 893 const uint8* additional, uint64 additional_length, |
| 739 uint64 add_id, uint64 track_number, | 894 uint64 add_id, uint64 track_number, |
| 740 uint64 abs_timecode, bool is_key); | 895 uint64 abs_timecode, bool is_key); |
| 741 | 896 |
| 742 // Adds a frame to be output in the file. The frame is written out through | 897 // Adds a frame to be output in the file. The frame is written out through |
| 743 // |writer_| if successful. Returns true on success. | 898 // |writer_| if successful. Returns true on success. |
| 744 // Inputs: | 899 // Inputs: |
| 745 // frame: Pointer to the data. | 900 // data: Pointer to the data. |
| 746 // length: Length of the data. | 901 // length: Length of the data. |
| 747 // discard_padding: DiscardPadding element value. | 902 // discard_padding: DiscardPadding element value. |
| 748 // track_number: Track to add the data to. Value returned by Add track | 903 // track_number: Track to add the data to. Value returned by Add track |
| 749 // functions. The range of allowed values is [1, 126]. | 904 // functions. The range of allowed values is [1, 126]. |
| 750 // abs_timecode: Absolute (not relative to cluster) timestamp of the | 905 // abs_timecode: Absolute (not relative to cluster) timestamp of the |
| 751 // frame, expressed in timecode units. | 906 // frame, expressed in timecode units. |
| 752 // is_key: Flag telling whether or not this frame is a key frame. | 907 // is_key: Flag telling whether or not this frame is a key frame. |
| 753 bool AddFrameWithDiscardPadding(const uint8* frame, uint64 length, | 908 bool AddFrameWithDiscardPadding(const uint8* data, uint64 length, |
| 754 int64 discard_padding, uint64 track_number, | 909 int64 discard_padding, uint64 track_number, |
| 755 uint64 abs_timecode, bool is_key); | 910 uint64 abs_timecode, bool is_key); |
| 756 | 911 |
| 757 // Writes a frame of metadata to the output medium; returns true on | 912 // Writes a frame of metadata to the output medium; returns true on |
| 758 // success. | 913 // success. |
| 759 // Inputs: | 914 // Inputs: |
| 760 // frame: Pointer to the data | 915 // data: Pointer to the data |
| 761 // length: Length of the data | 916 // length: Length of the data |
| 762 // track_number: Track to add the data to. Value returned by Add track | 917 // track_number: Track to add the data to. Value returned by Add track |
| 763 // functions. The range of allowed values is [1, 126]. | 918 // functions. The range of allowed values is [1, 126]. |
| 764 // timecode: Absolute (not relative to cluster) timestamp of the | 919 // timecode: Absolute (not relative to cluster) timestamp of the |
| 765 // metadata frame, expressed in timecode units. | 920 // metadata frame, expressed in timecode units. |
| 766 // duration: Duration of metadata frame, in timecode units. | 921 // duration: Duration of metadata frame, in timecode units. |
| 767 // | 922 // |
| 768 // The metadata frame is written as a block group, with a duration | 923 // The metadata frame is written as a block group, with a duration |
| 769 // sub-element but no reference time sub-elements (indicating that | 924 // sub-element but no reference time sub-elements (indicating that |
| 770 // it is considered a keyframe, per Matroska semantics). | 925 // it is considered a keyframe, per Matroska semantics). |
| 771 bool AddMetadata(const uint8* frame, uint64 length, uint64 track_number, | 926 bool AddMetadata(const uint8* data, uint64 length, uint64 track_number, |
| 772 uint64 timecode, uint64 duration); | 927 uint64 timecode, uint64 duration); |
| 773 | 928 |
| 774 // Increments the size of the cluster's data in bytes. | 929 // Increments the size of the cluster's data in bytes. |
| 775 void AddPayloadSize(uint64 size); | 930 void AddPayloadSize(uint64 size); |
| 776 | 931 |
| 777 // Closes the cluster so no more data can be written to it. Will update the | 932 // Closes the cluster so no more data can be written to it. Will update the |
| 778 // cluster's size if |writer_| is seekable. Returns true on success. | 933 // cluster's size if |writer_| is seekable. Returns true on success. |
| 779 bool Finalize(); | 934 bool Finalize(); |
| 780 | 935 |
| 781 // Returns the size in bytes for the entire Cluster element. | 936 // Returns the size in bytes for the entire Cluster element. |
| 782 uint64 Size() const; | 937 uint64 Size() const; |
| 783 | 938 |
| 939 // Given |abs_timecode|, calculates timecode relative to most recent timecode. |
| 940 // Returns -1 on failure, or a relative timecode. |
| 941 int64 GetRelativeTimecode(int64 abs_timecode) const; |
| 942 |
| 784 int64 size_position() const { return size_position_; } | 943 int64 size_position() const { return size_position_; } |
| 785 int32 blocks_added() const { return blocks_added_; } | 944 int32 blocks_added() const { return blocks_added_; } |
| 786 uint64 payload_size() const { return payload_size_; } | 945 uint64 payload_size() const { return payload_size_; } |
| 787 int64 position_for_cues() const { return position_for_cues_; } | 946 int64 position_for_cues() const { return position_for_cues_; } |
| 788 uint64 timecode() const { return timecode_; } | 947 uint64 timecode() const { return timecode_; } |
| 948 uint64 timecode_scale() const { return timecode_scale_; } |
| 789 | 949 |
| 790 private: | 950 private: |
| 791 // Signature that matches either of WriteSimpleBlock or WriteMetadataBlock | 951 // Utility method that confirms that blocks can still be added, and that the |
| 792 // in the muxer utilities package. | 952 // cluster header has been written. Used by |DoWriteFrame*|. Returns true |
| 793 typedef uint64 (*WriteBlock)(IMkvWriter* writer, const uint8* data, | 953 // when successful. |
| 794 uint64 length, uint64 track_number, | 954 bool PreWriteBlock(); |
| 795 int64 timecode, uint64 generic_arg); | |
| 796 | 955 |
| 797 // Signature that matches WriteBlockWithAdditional | 956 // Utility method used by the |DoWriteFrame*| methods that handles the book |
| 798 // in the muxer utilities package. | |
| 799 typedef uint64 (*WriteBlockAdditional)(IMkvWriter* writer, const uint8* data, | |
| 800 uint64 length, const uint8* additional, | |
| 801 uint64 add_id, | |
| 802 uint64 additional_length, | |
| 803 uint64 track_number, int64 timecode, | |
| 804 uint64 is_key); | |
| 805 | |
| 806 // Signature that matches WriteBlockWithDiscardPadding | |
| 807 // in the muxer utilities package. | |
| 808 typedef uint64 (*WriteBlockDiscardPadding)(IMkvWriter* writer, | |
| 809 const uint8* data, uint64 length, | |
| 810 int64 discard_padding, | |
| 811 uint64 track_number, | |
| 812 int64 timecode, uint64 is_key); | |
| 813 | |
| 814 // Utility method that confirms that blocks can still be added, and that the | |
| 815 // cluster header has been written. Used by |DoWriteBlock*|. Returns true | |
| 816 // when successful. | |
| 817 template <typename Type> | |
| 818 bool PreWriteBlock(Type* write_function); | |
| 819 | |
| 820 // Utility method used by the |DoWriteBlock*| methods that handles the book | |
| 821 // keeping required after each block is written. | 957 // keeping required after each block is written. |
| 822 void PostWriteBlock(uint64 element_size); | 958 void PostWriteBlock(uint64 element_size); |
| 823 | 959 |
| 824 // To simplify things, we require that there be fewer than 127 | 960 // Does some verification and calls WriteFrame. |
| 825 // tracks -- this allows us to serialize the track number value for | 961 bool DoWriteFrame(const Frame* const frame); |
| 826 // a stream using a single byte, per the Matroska encoding. | |
| 827 bool IsValidTrackNumber(uint64 track_number) const; | |
| 828 | |
| 829 // Given |abs_timecode|, calculates timecode relative to most recent timecode. | |
| 830 // Returns -1 on failure, or a relative timecode. | |
| 831 int64 GetRelativeTimecode(int64 abs_timecode) const; | |
| 832 | |
| 833 // Used to implement AddFrame and AddMetadata. | |
| 834 bool DoWriteBlock(const uint8* frame, uint64 length, uint64 track_number, | |
| 835 uint64 absolute_timecode, uint64 generic_arg, | |
| 836 WriteBlock write_block); | |
| 837 | |
| 838 // Used to implement AddFrameWithAdditional | |
| 839 bool DoWriteBlockWithAdditional(const uint8* frame, uint64 length, | |
| 840 const uint8* additional, | |
| 841 uint64 additional_length, uint64 add_id, | |
| 842 uint64 track_number, uint64 absolute_timecode, | |
| 843 uint64 generic_arg, | |
| 844 WriteBlockAdditional write_block); | |
| 845 | |
| 846 // Used to implement AddFrameWithDiscardPadding | |
| 847 bool DoWriteBlockWithDiscardPadding(const uint8* frame, uint64 length, | |
| 848 int64 discard_padding, | |
| 849 uint64 track_number, | |
| 850 uint64 absolute_timecode, | |
| 851 uint64 generic_arg, | |
| 852 WriteBlockDiscardPadding write_block); | |
| 853 | 962 |
| 854 // Outputs the Cluster header to |writer_|. Returns true on success. | 963 // Outputs the Cluster header to |writer_|. Returns true on success. |
| 855 bool WriteClusterHeader(); | 964 bool WriteClusterHeader(); |
| 856 | 965 |
| 857 // Number of blocks added to the cluster. | 966 // Number of blocks added to the cluster. |
| 858 int32 blocks_added_; | 967 int32 blocks_added_; |
| 859 | 968 |
| 860 // Flag telling if the cluster has been closed. | 969 // Flag telling if the cluster has been closed. |
| 861 bool finalized_; | 970 bool finalized_; |
| 862 | 971 |
| 863 // Flag telling if the cluster's header has been written. | 972 // Flag telling if the cluster's header has been written. |
| 864 bool header_written_; | 973 bool header_written_; |
| 865 | 974 |
| 866 // The size of the cluster elements in bytes. | 975 // The size of the cluster elements in bytes. |
| 867 uint64 payload_size_; | 976 uint64 payload_size_; |
| 868 | 977 |
| 869 // The file position used for cue points. | 978 // The file position used for cue points. |
| 870 const int64 position_for_cues_; | 979 const int64 position_for_cues_; |
| 871 | 980 |
| 872 // The file position of the cluster's size element. | 981 // The file position of the cluster's size element. |
| 873 int64 size_position_; | 982 int64 size_position_; |
| 874 | 983 |
| 875 // The absolute timecode of the cluster. | 984 // The absolute timecode of the cluster. |
| 876 const uint64 timecode_; | 985 const uint64 timecode_; |
| 877 | 986 |
| 987 // The timecode scale of the Segment containing the cluster. |
| 988 const uint64 timecode_scale_; |
| 989 |
| 878 // Pointer to the writer object. Not owned by this class. | 990 // Pointer to the writer object. Not owned by this class. |
| 879 IMkvWriter* writer_; | 991 IMkvWriter* writer_; |
| 880 | 992 |
| 881 LIBWEBM_DISALLOW_COPY_AND_ASSIGN(Cluster); | 993 LIBWEBM_DISALLOW_COPY_AND_ASSIGN(Cluster); |
| 882 }; | 994 }; |
| 883 | 995 |
| 884 /////////////////////////////////////////////////////////////// | 996 /////////////////////////////////////////////////////////////// |
| 885 // SeekHead element | 997 // SeekHead element |
| 886 class SeekHead { | 998 class SeekHead { |
| 887 public: | 999 public: |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 989 // |Init| must be called before any other method in this class. | 1101 // |Init| must be called before any other method in this class. |
| 990 class Segment { | 1102 class Segment { |
| 991 public: | 1103 public: |
| 992 enum Mode { kLive = 0x1, kFile = 0x2 }; | 1104 enum Mode { kLive = 0x1, kFile = 0x2 }; |
| 993 | 1105 |
| 994 enum CuesPosition { | 1106 enum CuesPosition { |
| 995 kAfterClusters = 0x0, // Position Cues after Clusters - Default | 1107 kAfterClusters = 0x0, // Position Cues after Clusters - Default |
| 996 kBeforeClusters = 0x1 // Position Cues before Clusters | 1108 kBeforeClusters = 0x1 // Position Cues before Clusters |
| 997 }; | 1109 }; |
| 998 | 1110 |
| 1111 const static uint32 kDefaultDocTypeVersion = 2; |
| 999 const static uint64 kDefaultMaxClusterDuration = 30000000000ULL; | 1112 const static uint64 kDefaultMaxClusterDuration = 30000000000ULL; |
| 1000 | 1113 |
| 1001 Segment(); | 1114 Segment(); |
| 1002 ~Segment(); | 1115 ~Segment(); |
| 1003 | 1116 |
| 1004 // Initializes |SegmentInfo| and returns result. Always returns false when | 1117 // Initializes |SegmentInfo| and returns result. Always returns false when |
| 1005 // |ptr_writer| is NULL. | 1118 // |ptr_writer| is NULL. |
| 1006 bool Init(IMkvWriter* ptr_writer); | 1119 bool Init(IMkvWriter* ptr_writer); |
| 1007 | 1120 |
| 1008 // Adds a generic track to the segment. Returns the newly-allocated | 1121 // Adds a generic track to the segment. Returns the newly-allocated |
| 1009 // track object (which is owned by the segment) on success, NULL on | 1122 // track object (which is owned by the segment) on success, NULL on |
| 1010 // error. |number| is the number to use for the track. |number| | 1123 // error. |number| is the number to use for the track. |number| |
| 1011 // must be >= 0. If |number| == 0 then the muxer will decide on the | 1124 // must be >= 0. If |number| == 0 then the muxer will decide on the |
| 1012 // track number. | 1125 // track number. |
| 1013 Track* AddTrack(int32 number); | 1126 Track* AddTrack(int32 number); |
| 1014 | 1127 |
| 1015 // Adds a Vorbis audio track to the segment. Returns the number of the track | 1128 // Adds a Vorbis audio track to the segment. Returns the number of the track |
| 1016 // on success, 0 on error. |number| is the number to use for the audio track. | 1129 // on success, 0 on error. |number| is the number to use for the audio track. |
| 1017 // |number| must be >= 0. If |number| == 0 then the muxer will decide on | 1130 // |number| must be >= 0. If |number| == 0 then the muxer will decide on |
| 1018 // the track number. | 1131 // the track number. |
| 1019 uint64 AddAudioTrack(int32 sample_rate, int32 channels, int32 number); | 1132 uint64 AddAudioTrack(int32 sample_rate, int32 channels, int32 number); |
| 1020 | 1133 |
| 1021 // Adds an empty chapter to the chapters of this segment. Returns | 1134 // Adds an empty chapter to the chapters of this segment. Returns |
| 1022 // non-NULL on success. After adding the chapter, the caller should | 1135 // non-NULL on success. After adding the chapter, the caller should |
| 1023 // populate its fields via the Chapter member functions. | 1136 // populate its fields via the Chapter member functions. |
| 1024 Chapter* AddChapter(); | 1137 Chapter* AddChapter(); |
| 1025 | 1138 |
| 1139 // Adds an empty tag to the tags of this segment. Returns |
| 1140 // non-NULL on success. After adding the tag, the caller should |
| 1141 // populate its fields via the Tag member functions. |
| 1142 Tag* AddTag(); |
| 1143 |
| 1026 // Adds a cue point to the Cues element. |timestamp| is the time in | 1144 // Adds a cue point to the Cues element. |timestamp| is the time in |
| 1027 // nanoseconds of the cue's time. |track| is the Track of the Cue. This | 1145 // nanoseconds of the cue's time. |track| is the Track of the Cue. This |
| 1028 // function must be called after AddFrame to calculate the correct | 1146 // function must be called after AddFrame to calculate the correct |
| 1029 // BlockNumber for the CuePoint. Returns true on success. | 1147 // BlockNumber for the CuePoint. Returns true on success. |
| 1030 bool AddCuePoint(uint64 timestamp, uint64 track); | 1148 bool AddCuePoint(uint64 timestamp, uint64 track); |
| 1031 | 1149 |
| 1032 // Adds a frame to be output in the file. Returns true on success. | 1150 // Adds a frame to be output in the file. Returns true on success. |
| 1033 // Inputs: | 1151 // Inputs: |
| 1034 // frame: Pointer to the data | 1152 // data: Pointer to the data |
| 1035 // length: Length of the data | 1153 // length: Length of the data |
| 1036 // track_number: Track to add the data to. Value returned by Add track | 1154 // track_number: Track to add the data to. Value returned by Add track |
| 1037 // functions. | 1155 // functions. |
| 1038 // timestamp: Timestamp of the frame in nanoseconds from 0. | 1156 // timestamp: Timestamp of the frame in nanoseconds from 0. |
| 1039 // is_key: Flag telling whether or not this frame is a key frame. | 1157 // is_key: Flag telling whether or not this frame is a key frame. |
| 1040 bool AddFrame(const uint8* frame, uint64 length, uint64 track_number, | 1158 bool AddFrame(const uint8* data, uint64 length, uint64 track_number, |
| 1041 uint64 timestamp_ns, bool is_key); | 1159 uint64 timestamp_ns, bool is_key); |
| 1042 | 1160 |
| 1043 // Writes a frame of metadata to the output medium; returns true on | 1161 // Writes a frame of metadata to the output medium; returns true on |
| 1044 // success. | 1162 // success. |
| 1045 // Inputs: | 1163 // Inputs: |
| 1046 // frame: Pointer to the data | 1164 // data: Pointer to the data |
| 1047 // length: Length of the data | 1165 // length: Length of the data |
| 1048 // track_number: Track to add the data to. Value returned by Add track | 1166 // track_number: Track to add the data to. Value returned by Add track |
| 1049 // functions. | 1167 // functions. |
| 1050 // timecode: Absolute timestamp of the metadata frame, expressed | 1168 // timecode: Absolute timestamp of the metadata frame, expressed |
| 1051 // in nanosecond units. | 1169 // in nanosecond units. |
| 1052 // duration: Duration of metadata frame, in nanosecond units. | 1170 // duration: Duration of metadata frame, in nanosecond units. |
| 1053 // | 1171 // |
| 1054 // The metadata frame is written as a block group, with a duration | 1172 // The metadata frame is written as a block group, with a duration |
| 1055 // sub-element but no reference time sub-elements (indicating that | 1173 // sub-element but no reference time sub-elements (indicating that |
| 1056 // it is considered a keyframe, per Matroska semantics). | 1174 // it is considered a keyframe, per Matroska semantics). |
| 1057 bool AddMetadata(const uint8* frame, uint64 length, uint64 track_number, | 1175 bool AddMetadata(const uint8* data, uint64 length, uint64 track_number, |
| 1058 uint64 timestamp_ns, uint64 duration_ns); | 1176 uint64 timestamp_ns, uint64 duration_ns); |
| 1059 | 1177 |
| 1060 // Writes a frame with additional data to the output medium; returns true on | 1178 // Writes a frame with additional data to the output medium; returns true on |
| 1061 // success. | 1179 // success. |
| 1062 // Inputs: | 1180 // Inputs: |
| 1063 // frame: Pointer to the data. | 1181 // data: Pointer to the data. |
| 1064 // length: Length of the data. | 1182 // length: Length of the data. |
| 1065 // additional: Pointer to additional data. | 1183 // additional: Pointer to additional data. |
| 1066 // additional_length: Length of additional data. | 1184 // additional_length: Length of additional data. |
| 1067 // add_id: Additional ID which identifies the type of additional data. | 1185 // add_id: Additional ID which identifies the type of additional data. |
| 1068 // track_number: Track to add the data to. Value returned by Add track | 1186 // track_number: Track to add the data to. Value returned by Add track |
| 1069 // functions. | 1187 // functions. |
| 1070 // timestamp: Absolute timestamp of the frame, expressed in nanosecond | 1188 // timestamp: Absolute timestamp of the frame, expressed in nanosecond |
| 1071 // units. | 1189 // units. |
| 1072 // is_key: Flag telling whether or not this frame is a key frame. | 1190 // is_key: Flag telling whether or not this frame is a key frame. |
| 1073 bool AddFrameWithAdditional(const uint8* frame, uint64 length, | 1191 bool AddFrameWithAdditional(const uint8* data, uint64 length, |
| 1074 const uint8* additional, uint64 additional_length, | 1192 const uint8* additional, uint64 additional_length, |
| 1075 uint64 add_id, uint64 track_number, | 1193 uint64 add_id, uint64 track_number, |
| 1076 uint64 timestamp, bool is_key); | 1194 uint64 timestamp, bool is_key); |
| 1077 | 1195 |
| 1078 // Writes a frame with DiscardPadding to the output medium; returns true on | 1196 // Writes a frame with DiscardPadding to the output medium; returns true on |
| 1079 // success. | 1197 // success. |
| 1080 // Inputs: | 1198 // Inputs: |
| 1081 // frame: Pointer to the data. | 1199 // data: Pointer to the data. |
| 1082 // length: Length of the data. | 1200 // length: Length of the data. |
| 1083 // discard_padding: DiscardPadding element value. | 1201 // discard_padding: DiscardPadding element value. |
| 1084 // track_number: Track to add the data to. Value returned by Add track | 1202 // track_number: Track to add the data to. Value returned by Add track |
| 1085 // functions. | 1203 // functions. |
| 1086 // timestamp: Absolute timestamp of the frame, expressed in nanosecond | 1204 // timestamp: Absolute timestamp of the frame, expressed in nanosecond |
| 1087 // units. | 1205 // units. |
| 1088 // is_key: Flag telling whether or not this frame is a key frame. | 1206 // is_key: Flag telling whether or not this frame is a key frame. |
| 1089 bool AddFrameWithDiscardPadding(const uint8* frame, uint64 length, | 1207 bool AddFrameWithDiscardPadding(const uint8* data, uint64 length, |
| 1090 int64 discard_padding, uint64 track_number, | 1208 int64 discard_padding, uint64 track_number, |
| 1091 uint64 timestamp, bool is_key); | 1209 uint64 timestamp, bool is_key); |
| 1092 | 1210 |
| 1093 // Writes a Frame to the output medium. Chooses the correct way of writing | 1211 // Writes a Frame to the output medium. Chooses the correct way of writing |
| 1094 // the frame (Block vs SimpleBlock) based on the parameters passed. | 1212 // the frame (Block vs SimpleBlock) based on the parameters passed. |
| 1095 // Inputs: | 1213 // Inputs: |
| 1096 // frame: frame object | 1214 // frame: frame object |
| 1097 bool AddGenericFrame(const Frame* frame); | 1215 bool AddGenericFrame(const Frame* frame); |
| 1098 | 1216 |
| 1099 // Adds a VP8 video track to the segment. Returns the number of the track on | 1217 // Adds a VP8 video track to the segment. Returns the number of the track on |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1170 CuesPosition cues_position() const { return cues_position_; } | 1288 CuesPosition cues_position() const { return cues_position_; } |
| 1171 bool output_cues() const { return output_cues_; } | 1289 bool output_cues() const { return output_cues_; } |
| 1172 const SegmentInfo* segment_info() const { return &segment_info_; } | 1290 const SegmentInfo* segment_info() const { return &segment_info_; } |
| 1173 | 1291 |
| 1174 private: | 1292 private: |
| 1175 // Checks if header information has been output and initialized. If not it | 1293 // Checks if header information has been output and initialized. If not it |
| 1176 // will output the Segment element and initialize the SeekHead elment and | 1294 // will output the Segment element and initialize the SeekHead elment and |
| 1177 // Cues elements. | 1295 // Cues elements. |
| 1178 bool CheckHeaderInfo(); | 1296 bool CheckHeaderInfo(); |
| 1179 | 1297 |
| 1298 // Sets |doc_type_version_| based on the current element requirements. |
| 1299 void UpdateDocTypeVersion(); |
| 1300 |
| 1180 // Sets |name| according to how many chunks have been written. |ext| is the | 1301 // Sets |name| according to how many chunks have been written. |ext| is the |
| 1181 // file extension. |name| must be deleted by the calling app. Returns true | 1302 // file extension. |name| must be deleted by the calling app. Returns true |
| 1182 // on success. | 1303 // on success. |
| 1183 bool UpdateChunkName(const char* ext, char** name) const; | 1304 bool UpdateChunkName(const char* ext, char** name) const; |
| 1184 | 1305 |
| 1185 // Returns the maximum offset within the segment's payload. When chunking | 1306 // Returns the maximum offset within the segment's payload. When chunking |
| 1186 // this function is needed to determine offsets of elements within the | 1307 // this function is needed to determine offsets of elements within the |
| 1187 // chunked files. Returns -1 on error. | 1308 // chunked files. Returns -1 on error. |
| 1188 int64 MaxOffset(); | 1309 int64 MaxOffset(); |
| 1189 | 1310 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1226 // reflect the correct offsets. | 1347 // reflect the correct offsets. |
| 1227 void MoveCuesBeforeClusters(); | 1348 void MoveCuesBeforeClusters(); |
| 1228 | 1349 |
| 1229 // This function recursively computes the correct cluster offsets (this is | 1350 // This function recursively computes the correct cluster offsets (this is |
| 1230 // done to move the Cues before Clusters). It recursively updates the change | 1351 // done to move the Cues before Clusters). It recursively updates the change |
| 1231 // in size (which indicates a change in cluster offset) until no sizes change. | 1352 // in size (which indicates a change in cluster offset) until no sizes change. |
| 1232 // Parameters: | 1353 // Parameters: |
| 1233 // diff - indicates the difference in size of the Cues element that needs to | 1354 // diff - indicates the difference in size of the Cues element that needs to |
| 1234 // accounted for. | 1355 // accounted for. |
| 1235 // index - index in the list of Cues which is currently being adjusted. | 1356 // index - index in the list of Cues which is currently being adjusted. |
| 1236 // cue_size - size of the Cues element. | 1357 // cue_size - sum of size of all the CuePoint elements. |
| 1237 void MoveCuesBeforeClustersHelper(uint64 diff, int index, uint64* cue_size); | 1358 void MoveCuesBeforeClustersHelper(uint64 diff, int index, uint64* cue_size); |
| 1238 | 1359 |
| 1239 // Seeds the random number generator used to make UIDs. | 1360 // Seeds the random number generator used to make UIDs. |
| 1240 unsigned int seed_; | 1361 unsigned int seed_; |
| 1241 | 1362 |
| 1242 // WebM elements | 1363 // WebM elements |
| 1243 Cues cues_; | 1364 Cues cues_; |
| 1244 SeekHead seek_head_; | 1365 SeekHead seek_head_; |
| 1245 SegmentInfo segment_info_; | 1366 SegmentInfo segment_info_; |
| 1246 Tracks tracks_; | 1367 Tracks tracks_; |
| 1247 Chapters chapters_; | 1368 Chapters chapters_; |
| 1369 Tags tags_; |
| 1248 | 1370 |
| 1249 // Number of chunks written. | 1371 // Number of chunks written. |
| 1250 int chunk_count_; | 1372 int chunk_count_; |
| 1251 | 1373 |
| 1252 // Current chunk filename. | 1374 // Current chunk filename. |
| 1253 char* chunk_name_; | 1375 char* chunk_name_; |
| 1254 | 1376 |
| 1255 // Default MkvWriter object created by this class used for writing clusters | 1377 // Default MkvWriter object created by this class used for writing clusters |
| 1256 // out in separate files. | 1378 // out in separate files. |
| 1257 MkvWriter* chunk_writer_cluster_; | 1379 MkvWriter* chunk_writer_cluster_; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1309 | 1431 |
| 1310 // Flag telling if the segment's header has been written. | 1432 // Flag telling if the segment's header has been written. |
| 1311 bool header_written_; | 1433 bool header_written_; |
| 1312 | 1434 |
| 1313 // Duration of the last block in nanoseconds. | 1435 // Duration of the last block in nanoseconds. |
| 1314 uint64 last_block_duration_; | 1436 uint64 last_block_duration_; |
| 1315 | 1437 |
| 1316 // Last timestamp in nanoseconds added to a cluster. | 1438 // Last timestamp in nanoseconds added to a cluster. |
| 1317 uint64 last_timestamp_; | 1439 uint64 last_timestamp_; |
| 1318 | 1440 |
| 1441 // Last timestamp in nanoseconds by track number added to a cluster. |
| 1442 uint64 last_track_timestamp_[kMaxTrackNumber]; |
| 1443 |
| 1319 // Maximum time in nanoseconds for a cluster duration. This variable is a | 1444 // Maximum time in nanoseconds for a cluster duration. This variable is a |
| 1320 // guideline and some clusters may have a longer duration. Default is 30 | 1445 // guideline and some clusters may have a longer duration. Default is 30 |
| 1321 // seconds. | 1446 // seconds. |
| 1322 uint64 max_cluster_duration_; | 1447 uint64 max_cluster_duration_; |
| 1323 | 1448 |
| 1324 // Maximum size in bytes for a cluster. This variable is a guideline and | 1449 // Maximum size in bytes for a cluster. This variable is a guideline and |
| 1325 // some clusters may have a larger size. Default is 0 which signifies that | 1450 // some clusters may have a larger size. Default is 0 which signifies that |
| 1326 // the muxer will decide the size. | 1451 // the muxer will decide the size. |
| 1327 uint64 max_cluster_size_; | 1452 uint64 max_cluster_size_; |
| 1328 | 1453 |
| 1329 // The mode that segment is in. If set to |kLive| the writer must not | 1454 // The mode that segment is in. If set to |kLive| the writer must not |
| 1330 // seek backwards. | 1455 // seek backwards. |
| 1331 Mode mode_; | 1456 Mode mode_; |
| 1332 | 1457 |
| 1333 // Flag telling the muxer that a new cue point should be added. | 1458 // Flag telling the muxer that a new cue point should be added. |
| 1334 bool new_cuepoint_; | 1459 bool new_cuepoint_; |
| 1335 | 1460 |
| 1336 // TODO(fgalligan): Should we add support for more than one Cues element? | 1461 // TODO(fgalligan): Should we add support for more than one Cues element? |
| 1337 // Flag whether or not the muxer should output a Cues element. | 1462 // Flag whether or not the muxer should output a Cues element. |
| 1338 bool output_cues_; | 1463 bool output_cues_; |
| 1339 | 1464 |
| 1465 // The size of the EBML header, used to validate the header if |
| 1466 // WriteEbmlHeader() is called more than once. |
| 1467 int32 ebml_header_size_; |
| 1468 |
| 1340 // The file position of the segment's payload. | 1469 // The file position of the segment's payload. |
| 1341 int64 payload_pos_; | 1470 int64 payload_pos_; |
| 1342 | 1471 |
| 1343 // The file position of the element's size. | 1472 // The file position of the element's size. |
| 1344 int64 size_position_; | 1473 int64 size_position_; |
| 1345 | 1474 |
| 1475 // Current DocTypeVersion (|doc_type_version_|) and that written in |
| 1476 // WriteSegmentHeader(). |
| 1477 // WriteEbmlHeader() will be called from Finalize() if |doc_type_version_| |
| 1478 // differs from |doc_type_version_written_|. |
| 1479 uint32 doc_type_version_; |
| 1480 uint32 doc_type_version_written_; |
| 1481 |
| 1346 // Pointer to the writer objects. Not owned by this class. | 1482 // Pointer to the writer objects. Not owned by this class. |
| 1347 IMkvWriter* writer_cluster_; | 1483 IMkvWriter* writer_cluster_; |
| 1348 IMkvWriter* writer_cues_; | 1484 IMkvWriter* writer_cues_; |
| 1349 IMkvWriter* writer_header_; | 1485 IMkvWriter* writer_header_; |
| 1350 | 1486 |
| 1351 LIBWEBM_DISALLOW_COPY_AND_ASSIGN(Segment); | 1487 LIBWEBM_DISALLOW_COPY_AND_ASSIGN(Segment); |
| 1352 }; | 1488 }; |
| 1353 | 1489 |
| 1354 } // end namespace mkvmuxer | 1490 } // end namespace mkvmuxer |
| 1355 | 1491 |
| 1356 #endif // MKVMUXER_HPP | 1492 #endif // MKVMUXER_HPP |
| OLD | NEW |