OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MEDIA_FILTERS_LIBWEBM_MUXER_H_ | 5 #ifndef MEDIA_FILTERS_LIBWEBM_MUXER_H_ |
6 #define MEDIA_FILTERS_LIBWEBM_MUXER_H_ | 6 #define MEDIA_FILTERS_LIBWEBM_MUXER_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/numerics/safe_math.h" | 9 #include "base/numerics/safe_math.h" |
10 #include "base/strings/string_piece.h" | 10 #include "base/strings/string_piece.h" |
11 #include "base/threading/thread_checker.h" | 11 #include "base/threading/thread_checker.h" |
12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
13 #include "media/base/media_export.h" | 13 #include "media/base/media_export.h" |
14 #include "media/base/video_codecs.h" | 14 #include "media/base/video_codecs.h" |
15 #include "third_party/libwebm/source/mkvmuxer.hpp" | 15 #include "third_party/libwebm/source/mkvmuxer.hpp" |
16 | 16 |
17 namespace gfx { | 17 namespace gfx { |
18 class Size; | 18 class Size; |
19 } // namespace gfx | 19 } // namespace gfx |
20 | 20 |
21 namespace media { | 21 namespace media { |
22 | 22 |
23 class VideoFrame; | 23 class VideoFrame; |
24 class AudioParameters; | |
24 | 25 |
25 // Adapter class to manage a WebM container [1], a simplified version of a | 26 // Adapter class to manage a WebM container [1], a simplified version of a |
26 // Matroska container [2], composed of an EBML header, and a single Segment | 27 // Matroska container [2], composed of an EBML header, and a single Segment |
27 // including at least a Track Section and a number of SimpleBlocks each | 28 // including at least a Track Section and a number of SimpleBlocks each |
28 // containing a single encoded video frame. WebM container has no Trailer. | 29 // containing a single encoded video frame. WebM container has no Trailer. |
29 // Clients will push encoded VPx video frames one by one via OnEncodedVideo(). | 30 // Clients will push encoded VPx video frames one by one via OnEncodedVideo(). |
30 // libwebm will eventually ping the WriteDataCB passed on contructor with the | 31 // libwebm will eventually ping the WriteDataCB passed on contructor with the |
31 // wrapped encoded data. | 32 // wrapped encoded data. |
32 // WebmMuxer is designed for single thread use throughout. | 33 // WebmMuxer is designed for single thread use throughout. |
33 // [1] http://www.webmproject.org/docs/container/ | 34 // [1] http://www.webmproject.org/docs/container/ |
34 // [2] http://www.matroska.org/technical/specs/index.html | 35 // [2] http://www.matroska.org/technical/specs/index.html |
35 // TODO(mcasas): Add support for Audio muxing. | 36 // TODO(mcasas): Add support for Audio muxing. |
36 class MEDIA_EXPORT WebmMuxer : public NON_EXPORTED_BASE(mkvmuxer::IMkvWriter) { | 37 class MEDIA_EXPORT WebmMuxer : public NON_EXPORTED_BASE(mkvmuxer::IMkvWriter) { |
37 public: | 38 public: |
38 // Callback to be called when WebmMuxer is ready to write a chunk of data, | 39 // Callback to be called when WebmMuxer is ready to write a chunk of data, |
39 // either any file header or a SingleBlock. | 40 // either any file header or a SingleBlock. |
40 using WriteDataCB = base::Callback<void(base::StringPiece)>; | 41 using WriteDataCB = base::Callback<void(base::StringPiece)>; |
41 | 42 |
42 // |codec| can be VP8 or VP9 and should coincide with whatever is sent in | 43 // |codec| can be VP8 or VP9 and should coincide with whatever is sent in |
43 // OnEncodedVideo(). | 44 // OnEncodedVideo(). |
44 WebmMuxer(VideoCodec codec, const WriteDataCB& write_data_callback); | 45 WebmMuxer(VideoCodec codec, |
46 size_t num_video_tracks, | |
47 size_t num_audio_tracks, | |
48 const WriteDataCB& write_data_callback); | |
45 ~WebmMuxer() override; | 49 ~WebmMuxer() override; |
46 | 50 |
47 // Adds a |video_frame| with |encoded_data.data()| to WebM Segment. | 51 // Functions to add video and audio frames with |encoded_data.data()| |
52 // to WebM Segment. | |
48 void OnEncodedVideo(const scoped_refptr<VideoFrame>& video_frame, | 53 void OnEncodedVideo(const scoped_refptr<VideoFrame>& video_frame, |
49 scoped_ptr<std::string> encoded_data, | 54 scoped_ptr<std::string> encoded_data, |
50 base::TimeTicks timestamp, | 55 base::TimeTicks timestamp, |
51 bool is_key_frame); | 56 bool is_key_frame); |
57 void OnEncodedAudio(const media::AudioParameters& params, | |
58 scoped_ptr<std::string> encoded_data, | |
59 base::TimeTicks timestamp); | |
52 | 60 |
53 private: | 61 private: |
54 friend class WebmMuxerTest; | 62 friend class WebmMuxerTest; |
55 | 63 |
56 // Creates and adds a new video track. Called upon receiving the first | 64 // Creates and adds a new video track. Called upon receiving the first |
57 // frame of a given Track, adds |frame_size| and |frame_rate| to the Segment | 65 // frame of a given Track, adds |frame_size| and |frame_rate| to the Segment |
58 // info, although individual frames passed to OnEncodedVideo() can have any | 66 // info, although individual frames passed to OnEncodedVideo() can have any |
59 // frame size. | 67 // frame size. |
60 void AddVideoTrack(const gfx::Size& frame_size, double frame_rate); | 68 void AddVideoTrack(const gfx::Size& frame_size, double frame_rate); |
61 | 69 |
70 // Creates and adds a new audio track. bla bla bla | |
mcasas
2015/10/28 00:42:02
:)
ajose
2015/10/28 23:43:47
oy vey
| |
71 void AddAudioTrack(const media::AudioParameters& params); | |
72 | |
62 // IMkvWriter interface. | 73 // IMkvWriter interface. |
63 mkvmuxer::int32 Write(const void* buf, mkvmuxer::uint32 len) override; | 74 mkvmuxer::int32 Write(const void* buf, mkvmuxer::uint32 len) override; |
64 mkvmuxer::int64 Position() const override; | 75 mkvmuxer::int64 Position() const override; |
65 mkvmuxer::int32 Position(mkvmuxer::int64 position) override; | 76 mkvmuxer::int32 Position(mkvmuxer::int64 position) override; |
66 bool Seekable() const override; | 77 bool Seekable() const override; |
67 void ElementStartNotify(mkvmuxer::uint64 element_id, | 78 void ElementStartNotify(mkvmuxer::uint64 element_id, |
68 mkvmuxer::int64 position) override; | 79 mkvmuxer::int64 position) override; |
69 | 80 |
70 // Used to DCHECK that we are called on the correct thread. | 81 // Used to DCHECK that we are called on the correct thread. |
71 base::ThreadChecker thread_checker_; | 82 base::ThreadChecker thread_checker_; |
72 | 83 |
73 // Video Codec configured: VP9 if true, otherwise VP8 is used by default. | 84 // Video Codec configured: VP9 if true, otherwise VP8 is used by default. |
74 const bool use_vp9_; | 85 const bool use_vp9_; |
75 | 86 |
76 // A caller-side identifier to interact with |segment_|, initialised upon | 87 // Caller-side identifiers to interact with |segment_|, initialised upon |
77 // first frame arrival by AddVideoTrack(). | 88 // first frame arrival to Add{Video, Audio}Track(). |
78 uint64_t track_index_; | 89 uint64_t video_track_index_; |
90 uint64_t audio_track_index_; | |
79 | 91 |
80 // Origin of times for frame timestamps. | 92 // Origin of times for frame timestamps. |
81 base::TimeTicks first_frame_timestamp_; | 93 base::TimeTicks first_frame_timestamp_; |
94 base::TimeDelta most_recent_timestamp_; | |
95 | |
96 bool has_video_; | |
97 bool has_audio_; | |
82 | 98 |
83 // Callback to dump written data as being called by libwebm. | 99 // Callback to dump written data as being called by libwebm. |
84 const WriteDataCB write_data_callback_; | 100 const WriteDataCB write_data_callback_; |
85 | 101 |
86 // Rolling counter of the position in bytes of the written goo. | 102 // Rolling counter of the position in bytes of the written goo. |
87 base::CheckedNumeric<mkvmuxer::int64> position_; | 103 base::CheckedNumeric<mkvmuxer::int64> position_; |
88 | 104 |
89 // The MkvMuxer active element. | 105 // The MkvMuxer active element. |
90 mkvmuxer::Segment segment_; | 106 mkvmuxer::Segment segment_; |
91 | 107 |
92 DISALLOW_COPY_AND_ASSIGN(WebmMuxer); | 108 DISALLOW_COPY_AND_ASSIGN(WebmMuxer); |
93 }; | 109 }; |
94 | 110 |
95 } // namespace media | 111 } // namespace media |
96 | 112 |
97 #endif // MEDIA_FILTERS_LIBWEBM_MUXER_H_ | 113 #endif // MEDIA_FILTERS_LIBWEBM_MUXER_H_ |
OLD | NEW |