Chromium Code Reviews| 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 or audio frame. WebM container has no |
| 29 // Clients will push encoded VPx video frames one by one via OnEncodedVideo(). | 30 // Trailer. |
| 30 // libwebm will eventually ping the WriteDataCB passed on contructor with the | 31 // Clients will push encoded VPx video frames and Opus audio frames one by one |
| 32 // via OnEncoded{Video|Audio}(). libwebm will eventually ping the WriteDataCB | |
| 33 // passed on contructor with the | |
|
mcasas
2015/11/06 02:22:37
Reflow l.33-34
ajose
2015/11/06 18:40:52
Done.
| |
| 31 // wrapped encoded data. | 34 // wrapped encoded data. |
| 32 // WebmMuxer is designed for single thread use throughout. | 35 // WebmMuxer is designed for use on a single thread. |
| 33 // [1] http://www.webmproject.org/docs/container/ | 36 // [1] http://www.webmproject.org/docs/container/ |
| 34 // [2] http://www.matroska.org/technical/specs/index.html | 37 // [2] http://www.matroska.org/technical/specs/index.html |
| 35 // TODO(mcasas): Add support for Audio muxing. | |
| 36 class MEDIA_EXPORT WebmMuxer : public NON_EXPORTED_BASE(mkvmuxer::IMkvWriter) { | 38 class MEDIA_EXPORT WebmMuxer : public NON_EXPORTED_BASE(mkvmuxer::IMkvWriter) { |
| 37 public: | 39 public: |
| 38 // Callback to be called when WebmMuxer is ready to write a chunk of data, | 40 // Callback to be called when WebmMuxer is ready to write a chunk of data, |
| 39 // either any file header or a SingleBlock. | 41 // either any file header or a SingleBlock. |
| 40 using WriteDataCB = base::Callback<void(base::StringPiece)>; | 42 using WriteDataCB = base::Callback<void(base::StringPiece)>; |
| 41 | 43 |
| 42 // |codec| can be VP8 or VP9 and should coincide with whatever is sent in | 44 // |codec| can be VP8 or VP9 and should coincide with whatever is sent in |
| 43 // OnEncodedVideo(). | 45 // OnEncodedVideo(). |
| 44 WebmMuxer(VideoCodec codec, const WriteDataCB& write_data_callback); | 46 WebmMuxer(VideoCodec codec, |
| 47 uint8_t num_video_tracks, | |
| 48 uint8_t num_audio_tracks, | |
| 49 const WriteDataCB& write_data_callback); | |
| 45 ~WebmMuxer() override; | 50 ~WebmMuxer() override; |
| 46 | 51 |
| 47 // Adds a |video_frame| with |encoded_data.data()| to WebM Segment. | 52 // Functions to add video and audio frames with |encoded_data.data()| |
| 53 // to WebM Segment. | |
| 48 void OnEncodedVideo(const scoped_refptr<VideoFrame>& video_frame, | 54 void OnEncodedVideo(const scoped_refptr<VideoFrame>& video_frame, |
| 49 scoped_ptr<std::string> encoded_data, | 55 scoped_ptr<std::string> encoded_data, |
| 50 base::TimeTicks timestamp, | 56 base::TimeTicks timestamp, |
| 51 bool is_key_frame); | 57 bool is_key_frame); |
| 58 void OnEncodedAudio(const media::AudioParameters& params, | |
| 59 scoped_ptr<std::string> encoded_data, | |
| 60 base::TimeTicks timestamp); | |
| 52 | 61 |
| 53 private: | 62 private: |
| 54 friend class WebmMuxerTest; | 63 friend class WebmMuxerTest; |
| 55 | 64 |
| 56 // Creates and adds a new video track. Called upon receiving the first | 65 // 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 | 66 // receiving the first frame of a given Track. |
| 67 // AddVideoTrack adds |frame_size| and |frame_rate| to the Segment | |
| 58 // info, although individual frames passed to OnEncodedVideo() can have any | 68 // info, although individual frames passed to OnEncodedVideo() can have any |
| 59 // frame size. | 69 // frame size. |
| 60 void AddVideoTrack(const gfx::Size& frame_size, double frame_rate); | 70 void AddVideoTrack(const gfx::Size& frame_size, double frame_rate); |
| 71 void AddAudioTrack(const media::AudioParameters& params); | |
| 61 | 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 uint8_t video_track_index_; |
| 90 uint8_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 // The expected total number of video and audio tracks. | |
| 97 const uint8_t num_video_tracks_; | |
| 98 const uint8_t num_audio_tracks_; | |
|
mcasas
2015/11/06 02:22:37
Since for this CL we don't support
|num_video_trac
ajose
2015/11/06 18:40:52
Done.
| |
| 82 | 99 |
| 83 // Callback to dump written data as being called by libwebm. | 100 // Callback to dump written data as being called by libwebm. |
| 84 const WriteDataCB write_data_callback_; | 101 const WriteDataCB write_data_callback_; |
| 85 | 102 |
| 86 // Rolling counter of the position in bytes of the written goo. | 103 // Rolling counter of the position in bytes of the written goo. |
| 87 base::CheckedNumeric<mkvmuxer::int64> position_; | 104 base::CheckedNumeric<mkvmuxer::int64> position_; |
| 88 | 105 |
| 89 // The MkvMuxer active element. | 106 // The MkvMuxer active element. |
| 90 mkvmuxer::Segment segment_; | 107 mkvmuxer::Segment segment_; |
| 91 | 108 |
| 92 DISALLOW_COPY_AND_ASSIGN(WebmMuxer); | 109 DISALLOW_COPY_AND_ASSIGN(WebmMuxer); |
| 93 }; | 110 }; |
| 94 | 111 |
| 95 } // namespace media | 112 } // namespace media |
| 96 | 113 |
| 97 #endif // MEDIA_FILTERS_LIBWEBM_MUXER_H_ | 114 #endif // MEDIA_FILTERS_LIBWEBM_MUXER_H_ |
| OLD | NEW |