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(). |
mcasas
2015/11/05 02:08:20
Update these lines plz.
ajose
2015/11/05 19:02:58
Done.
| |
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 uint8_t num_video_tracks, | |
47 uint8_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 // Methods for creating and adding video and audio tracks, called upon |
57 // frame of a given Track, adds |frame_size| and |frame_rate| to the Segment | 65 // receiving the first frame of a given Track. |
66 // AddVideoTrack adds |frame_size| and |frame_rate| to the Segment | |
58 // info, although individual frames passed to OnEncodedVideo() can have any | 67 // info, although individual frames passed to OnEncodedVideo() can have any |
59 // frame size. | 68 // frame size. |
60 void AddVideoTrack(const gfx::Size& frame_size, double frame_rate); | 69 void AddVideoTrack(const gfx::Size& frame_size, double frame_rate); |
70 void AddAudioTrack(const media::AudioParameters& params); | |
61 | 71 |
62 // IMkvWriter interface. | 72 // IMkvWriter interface. |
63 mkvmuxer::int32 Write(const void* buf, mkvmuxer::uint32 len) override; | 73 mkvmuxer::int32 Write(const void* buf, mkvmuxer::uint32 len) override; |
64 mkvmuxer::int64 Position() const override; | 74 mkvmuxer::int64 Position() const override; |
65 mkvmuxer::int32 Position(mkvmuxer::int64 position) override; | 75 mkvmuxer::int32 Position(mkvmuxer::int64 position) override; |
66 bool Seekable() const override; | 76 bool Seekable() const override; |
67 void ElementStartNotify(mkvmuxer::uint64 element_id, | 77 void ElementStartNotify(mkvmuxer::uint64 element_id, |
68 mkvmuxer::int64 position) override; | 78 mkvmuxer::int64 position) override; |
69 | 79 |
70 // Used to DCHECK that we are called on the correct thread. | 80 // Used to DCHECK that we are called on the correct thread. |
71 base::ThreadChecker thread_checker_; | 81 base::ThreadChecker thread_checker_; |
72 | 82 |
73 // Video Codec configured: VP9 if true, otherwise VP8 is used by default. | 83 // Video Codec configured: VP9 if true, otherwise VP8 is used by default. |
74 const bool use_vp9_; | 84 const bool use_vp9_; |
75 | 85 |
76 // A caller-side identifier to interact with |segment_|, initialised upon | 86 // Caller-side identifiers to interact with |segment_|, initialised upon |
77 // first frame arrival by AddVideoTrack(). | 87 // first frame arrival to Add{Video, Audio}Track(). |
78 uint64_t track_index_; | 88 uint8_t video_track_index_; |
89 uint8_t audio_track_index_; | |
79 | 90 |
80 // Origin of times for frame timestamps. | 91 // Origin of times for frame timestamps. |
81 base::TimeTicks first_frame_timestamp_; | 92 base::TimeTicks first_frame_timestamp_; |
93 base::TimeDelta most_recent_timestamp_; | |
94 | |
95 // The expected total number of video and audio tracks. | |
96 const uint8_t num_video_tracks_; | |
97 const uint8_t num_audio_tracks_; | |
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 |