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, a simplified version of a Matroska | |
22 // container [1], composed of an EBML header, and a single Segment including | |
23 // at least a Track Section and a number of SimpleBlocks each containing a | |
24 // 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.matroska.org/technical/specs/index.html | |
31 // TODO(mcasas): Add support for Audio muxing. | |
32 class MEDIA_EXPORT WebmMuxer : public mkvmuxer::IMkvWriter { | |
33 public: | |
34 // Callback to be called when WebmMuxer is ready to write a chunk of data, | |
35 // either any file header or a SingleBlock. The chunk is described as a byte | |
36 // array and a byte length. | |
37 typedef base::Callback<void(const char*, size_t)> WriteDataCB; | |
38 | |
39 explicit WebmMuxer(const WriteDataCB& write_data_callback); | |
40 ~WebmMuxer() override; | |
41 | |
42 // Creates and adds a new video track. Called before receiving the first | |
43 // frame of a given Track, adds |frame_size| and |frame_rate| to the Segment | |
44 // info, although individual frames passed to OnEncodedVideo() can have any | |
45 // frame size. | |
46 void AddVideoTrack(uint32_t track_number, | |
47 const gfx::Size& frame_size, | |
48 double frame_rate); | |
49 | |
50 // Adds a frame with |encoded_data.data()| to WebM Segment. |track_number| is | |
51 // a caller-side identifier and must have been AddVideoTrack()ed before. | |
52 void OnEncodedVideo(uint32_t track_number, | |
53 const std::string& encoded_data, | |
54 const base::TimeDelta& timestamp, | |
55 bool keyframe); | |
56 | |
57 private: | |
58 friend class WebmMuxerTest; | |
DaleCurtis
2015/07/20 18:45:17
Why both this and the FRIEND_TEST....
mcasas
2015/07/20 20:15:20
Both are needed for the individual tests to access
DaleCurtis
2015/07/20 20:23:07
Just add accessors to the WebmMuxerTest harness. I
mcasas
2015/07/21 12:56:20
Done.
| |
59 FRIEND_TEST_ALL_PREFIXES(WebmMuxerTest, AddVideoTrack); | |
60 FRIEND_TEST_ALL_PREFIXES(WebmMuxerTest, Write); | |
61 FRIEND_TEST_ALL_PREFIXES(WebmMuxerTest, OnEncodedVideoEmptyAndNormalFrames); | |
62 FRIEND_TEST_ALL_PREFIXES(WebmMuxerTest, OnEncodedVideoNormalFrames); | |
63 | |
64 // IMkvWriter interface. | |
65 mkvmuxer::int32 Write(const void* buf, mkvmuxer::uint32 len) override; | |
66 mkvmuxer::int64 Position() const override; | |
67 mkvmuxer::int32 Position(mkvmuxer::int64 position) override; | |
68 bool Seekable() const override; | |
69 void ElementStartNotify(mkvmuxer::uint64 element_id, | |
70 mkvmuxer::int64 position) override; | |
71 | |
72 // Used to DCHECK that we are called on the correct thread. | |
73 base::ThreadChecker thread_checker_; | |
74 | |
75 // Callback to dump written data as being called by libwebm. | |
76 const WriteDataCB write_data_callback_; | |
77 | |
78 // Rolling counter of the position in bytes of the written goo. | |
79 base::CheckedNumeric<mkvmuxer::int64> position_; | |
80 | |
81 // Owned pointer to the MkvMuxer active element. | |
82 const scoped_ptr<mkvmuxer::Segment> segment_; | |
DaleCurtis
2015/07/20 18:45:17
Why const scoped_ptr? Just use a mkvmuxer::Segment
mcasas
2015/07/20 20:15:20
Done.
| |
83 | |
84 DISALLOW_COPY_AND_ASSIGN(WebmMuxer); | |
85 }; | |
86 | |
87 } // namespace media | |
88 | |
89 #endif // MEDIA_FILTERS_LIBWEBM_MUXER_H_ | |
OLD | NEW |