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 "packager/base/memory/scoped_ptr.h"
10 
11 namespace shaka {
12 namespace media {
13 
14 class Cluster {
15  public:
16  Cluster(scoped_ptr<uint8_t[]> data, int size);
17  ~Cluster();
18 
19  const uint8_t* data() const { return data_.get(); }
20  int size() const { return size_; }
21 
22  private:
23  scoped_ptr<uint8_t[]> data_;
24  int size_;
25 
26  DISALLOW_IMPLICIT_CONSTRUCTORS(Cluster);
27 };
28 
30  public:
32  ~ClusterBuilder();
33 
34  void SetClusterTimecode(int64_t cluster_timecode);
35  void AddSimpleBlock(int track_num,
36  int64_t timecode,
37  int flags,
38  const uint8_t* data,
39  int size);
40  void AddBlockGroup(int track_num,
41  int64_t timecode,
42  int duration,
43  int flags,
44  bool is_key_frame,
45  const uint8_t* data,
46  int size);
47  void AddBlockGroupWithoutBlockDuration(int track_num,
48  int64_t timecode,
49  int flags,
50  bool is_key_frame,
51  const uint8_t* data,
52  int size);
53 
54  scoped_ptr<Cluster> Finish();
55  scoped_ptr<Cluster> FinishWithUnknownSize();
56 
57  private:
58  void AddBlockGroupInternal(int track_num,
59  int64_t timecode,
60  bool include_block_duration,
61  int duration,
62  int flags,
63  bool is_key_frame,
64  const uint8_t* data,
65  int size);
66  void Reset();
67  void ExtendBuffer(int bytes_needed);
68  void UpdateUInt64(int offset, int64_t value);
69  void WriteBlock(uint8_t* buf,
70  int track_num,
71  int64_t timecode,
72  int flags,
73  const uint8_t* data,
74  int size);
75 
76  scoped_ptr<uint8_t[]> buffer_;
77  int buffer_size_;
78  int bytes_used_;
79  int64_t cluster_timecode_;
80 
81  DISALLOW_COPY_AND_ASSIGN(ClusterBuilder);
82 };
83 
84 } // namespace media
85 } // namespace shaka
86 
87 #endif // MEDIA_FORMATS_WEBM_CLUSTER_BUILDER_H_