OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 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_FILTERS_LIBWEBM_MUXER_H_ | |
6 #define MEDIA_FILTERS_LIBWEBM_MUXER_H_ | |
7 | |
8 #include <set> | |
9 | |
10 #include "base/callback.h" | |
11 #include "base/gtest_prod_util.h" | |
12 #include "base/numerics/safe_math.h" | |
13 #include "base/threading/thread_checker.h" | |
14 #include "base/time/time.h" | |
15 #include "media/base/media_export.h" | |
16 #include "third_party/libwebm/source/mkvmuxer.hpp" | |
17 #include "ui/gfx/geometry/size.h" | |
18 | |
19 namespace media { | |
20 | |
21 // Adapter class to manage a WebM container [1], a simplified version of a | |
22 // Matroska container [2], composed of an EBML header, and a single Segment | |
23 // including at least a Track Section and a number of SimpleBlocks each | |
24 // containing a single encoded video frame. WebM container has no Trailer. | |
25 // Clients will push encoded VPx video frames one by one via OnEncodedVideo() | |
26 // with indication of the Track they belong to, and libwebm will eventually ping | |
27 // the WriteDataCB passed on contructor with the wrapped encoded data. All | |
28 // operations must happen in a single thread, where WebmMuxer is created and | |
29 // destroyed. | |
30 // [1] http://www.webmproject.org/docs/container/ | |
31 // [2] http://www.matroska.org/technical/specs/index.html | |
32 // TODO(mcasas): Add support for Audio muxing. | |
33 class MEDIA_EXPORT WebmMuxer : public mkvmuxer::IMkvWriter { | |
34 public: | |
35 // Callback to be called when WebmMuxer is ready to write a chunk of data, | |
36 // either any file header or a SingleBlock. The chunk is described as a byte | |
37 // array and a byte length. | |
38 using WriteDataCB = base::Callback<void(const char*, size_t)>; | |
DaleCurtis
2015/07/22 18:19:17
You use char* here and uint8_t* below (and void* o
mcasas
2015/07/23 10:05:14
using base::StringPiece now.
| |
39 | |
40 explicit WebmMuxer(const WriteDataCB& write_data_callback); | |
41 ~WebmMuxer() override; | |
42 | |
43 // Creates and adds a new video track. Called before receiving the first | |
44 // frame of a given Track, adds |frame_size| and |frame_rate| to the Segment | |
45 // info, although individual frames passed to OnEncodedVideo() can have any | |
46 // frame size. Returns the track_index to be used for OnEncodedVideo(). | |
47 uint64_t AddVideoTrack(const gfx::Size& frame_size, double frame_rate); | |
48 | |
49 // Adds a frame with |encoded_data.data()| to WebM Segment. |track_number| is | |
50 // a caller-side identifier and must have been provided by AddVideoTrack(). | |
51 // TODO(mcasas): Revisit how |encoded_data| is passed once the whole recording | |
52 // chain is setup (http://crbug.com/262211) | |
53 void OnEncodedVideo(uint64_t track_number, | |
54 const uint8_t* encoded_data, | |
55 size_t encoded_data_len, | |
56 base::TimeDelta timestamp, | |
57 bool keyframe); | |
58 | |
59 private: | |
60 friend class WebmMuxerTest; | |
61 | |
62 // IMkvWriter interface. | |
63 mkvmuxer::int32 Write(const void* buf, mkvmuxer::uint32 len) override; | |
64 mkvmuxer::int64 Position() const override; | |
65 mkvmuxer::int32 Position(mkvmuxer::int64 position) override; | |
66 bool Seekable() const override; | |
67 void ElementStartNotify(mkvmuxer::uint64 element_id, | |
68 mkvmuxer::int64 position) override; | |
69 | |
70 // Used to DCHECK that we are called on the correct thread. | |
71 base::ThreadChecker thread_checker_; | |
72 | |
73 // Callback to dump written data as being called by libwebm. | |
74 const WriteDataCB write_data_callback_; | |
75 | |
76 // Rolling counter of the position in bytes of the written goo. | |
77 base::CheckedNumeric<mkvmuxer::int64> position_; | |
78 | |
79 // The MkvMuxer active element. | |
80 mkvmuxer::Segment segment_; | |
81 | |
82 DISALLOW_COPY_AND_ASSIGN(WebmMuxer); | |
83 }; | |
84 | |
85 } // namespace media | |
86 | |
87 #endif // MEDIA_FILTERS_LIBWEBM_MUXER_H_ | |
OLD | NEW |