DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator
cluster_builder.h
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef MEDIA_FORMATS_WEBM_CLUSTER_BUILDER_H_
6 #define MEDIA_FORMATS_WEBM_CLUSTER_BUILDER_H_
7 
8 #include <stdint.h>
9 #include <memory>
10 
11 #include "packager/base/macros.h"
12 
13 namespace shaka {
14 namespace media {
15 
16 class Cluster {
17  public:
18  Cluster(std::unique_ptr<uint8_t[]> data, int size);
19  ~Cluster();
20 
21  const uint8_t* data() const { return data_.get(); }
22  int size() const { return size_; }
23 
24  private:
25  std::unique_ptr<uint8_t[]> data_;
26  int size_;
27 
28  DISALLOW_IMPLICIT_CONSTRUCTORS(Cluster);
29 };
30 
32  public:
34  ~ClusterBuilder();
35 
36  void SetClusterTimecode(int64_t cluster_timecode);
37  void AddSimpleBlock(int track_num,
38  int64_t timecode,
39  int flags,
40  const uint8_t* data,
41  int size);
42  void AddBlockGroup(int track_num,
43  int64_t timecode,
44  int duration,
45  int flags,
46  bool is_key_frame,
47  const uint8_t* data,
48  int size);
49  void AddBlockGroupWithoutBlockDuration(int track_num,
50  int64_t timecode,
51  int flags,
52  bool is_key_frame,
53  const uint8_t* data,
54  int size);
55 
56  std::unique_ptr<Cluster> Finish();
57  std::unique_ptr<Cluster> FinishWithUnknownSize();
58 
59  private:
60  void AddBlockGroupInternal(int track_num,
61  int64_t timecode,
62  bool include_block_duration,
63  int duration,
64  int flags,
65  bool is_key_frame,
66  const uint8_t* data,
67  int size);
68  void Reset();
69  void ExtendBuffer(int bytes_needed);
70  void UpdateUInt64(int offset, int64_t value);
71  void WriteBlock(uint8_t* buf,
72  int track_num,
73  int64_t timecode,
74  int flags,
75  const uint8_t* data,
76  int size);
77 
78  std::unique_ptr<uint8_t[]> buffer_;
79  int buffer_size_;
80  int bytes_used_;
81  int64_t cluster_timecode_;
82 
83  DISALLOW_COPY_AND_ASSIGN(ClusterBuilder);
84 };
85 
86 } // namespace media
87 } // namespace shaka
88 
89 #endif // MEDIA_FORMATS_WEBM_CLUSTER_BUILDER_H_