• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "media/base/buffers.h"
11 
12 namespace media {
13 
14 class Cluster {
15  public:
16   Cluster(scoped_ptr<uint8[]> data, int size);
17   ~Cluster();
18 
data()19   const uint8* data() const { return data_.get(); }
size()20   int size() const { return size_; }
21 
22  private:
23   scoped_ptr<uint8[]> data_;
24   int size_;
25 
26   DISALLOW_IMPLICIT_CONSTRUCTORS(Cluster);
27 };
28 
29 class ClusterBuilder {
30  public:
31   ClusterBuilder();
32   ~ClusterBuilder();
33 
34   void SetClusterTimecode(int64 cluster_timecode);
35   void AddSimpleBlock(int track_num, int64 timecode, int flags,
36                       const uint8* data, int size);
37   void AddBlockGroup(int track_num, int64 timecode, int duration, int flags,
38                      const uint8* data, int size);
39   void AddBlockGroupWithoutBlockDuration(int track_num, int64 timecode,
40                      int flags, const uint8* data, int size);
41 
42   scoped_ptr<Cluster> Finish();
43   scoped_ptr<Cluster> FinishWithUnknownSize();
44 
45  private:
46   void AddBlockGroupInternal(int track_num, int64 timecode,
47                              bool include_block_duration, int duration,
48                              int flags, const uint8* data, int size);
49   void Reset();
50   void ExtendBuffer(int bytes_needed);
51   void UpdateUInt64(int offset, int64 value);
52   void WriteBlock(uint8* buf, int track_num, int64 timecode, int flags,
53                   const uint8* data, int size);
54 
55   scoped_ptr<uint8[]> buffer_;
56   int buffer_size_;
57   int bytes_used_;
58   int64 cluster_timecode_;
59 
60   DISALLOW_COPY_AND_ASSIGN(ClusterBuilder);
61 };
62 
63 }  // namespace media
64 
65 #endif  // MEDIA_FORMATS_WEBM_CLUSTER_BUILDER_H_
66