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  const uint8_t* data,
45  int size);
46  void AddBlockGroupWithoutBlockDuration(int track_num,
47  int64_t timecode,
48  int flags,
49  const uint8_t* data,
50  int size);
51 
52  scoped_ptr<Cluster> Finish();
53  scoped_ptr<Cluster> FinishWithUnknownSize();
54 
55  private:
56  void AddBlockGroupInternal(int track_num,
57  int64_t timecode,
58  bool include_block_duration,
59  int duration,
60  int flags,
61  const uint8_t* data,
62  int size);
63  void Reset();
64  void ExtendBuffer(int bytes_needed);
65  void UpdateUInt64(int offset, int64_t value);
66  void WriteBlock(uint8_t* buf,
67  int track_num,
68  int64_t timecode,
69  int flags,
70  const uint8_t* data,
71  int size);
72 
73  scoped_ptr<uint8_t[]> buffer_;
74  int buffer_size_;
75  int bytes_used_;
76  int64_t cluster_timecode_;
77 
78  DISALLOW_COPY_AND_ASSIGN(ClusterBuilder);
79 };
80 
81 } // namespace media
82 } // namespace shaka
83 
84 #endif // MEDIA_FORMATS_WEBM_CLUSTER_BUILDER_H_