| 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_MUXERS_WEBM_MUXER_H_ | 5 #ifndef MEDIA_MUXERS_WEBM_MUXER_H_ |
| 6 #define MEDIA_MUXERS_WEBM_MUXER_H_ | 6 #define MEDIA_MUXERS_WEBM_MUXER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <deque> | 10 #include <deque> |
| 11 #include <memory> | 11 #include <memory> |
| 12 | 12 |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/numerics/safe_math.h" | 15 #include "base/numerics/safe_math.h" |
| 16 #include "base/strings/string_piece.h" | 16 #include "base/strings/string_piece.h" |
| 17 #include "base/threading/thread_checker.h" | 17 #include "base/threading/thread_checker.h" |
| 18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
| 19 #include "base/timer/elapsed_timer.h" | 19 #include "base/timer/elapsed_timer.h" |
| 20 #include "media/base/media_export.h" | 20 #include "media/base/media_export.h" |
| 21 #include "media/base/video_codecs.h" | 21 #include "media/base/video_codecs.h" |
| 22 #include "third_party/libwebm/source/mkvmuxer.hpp" | 22 #include "third_party/libwebm/source/mkvmuxer.hpp" |
| 23 #include "ui/gfx/geometry/size.h" |
| 23 | 24 |
| 24 namespace gfx { | 25 namespace gfx { |
| 25 class Size; | 26 class Size; |
| 26 } // namespace gfx | 27 } // namespace gfx |
| 27 | 28 |
| 28 namespace media { | 29 namespace media { |
| 29 | 30 |
| 30 class VideoFrame; | 31 class VideoFrame; |
| 31 class AudioParameters; | 32 class AudioParameters; |
| 32 | 33 |
| 33 // Adapter class to manage a WebM container [1], a simplified version of a | 34 // Adapter class to manage a WebM container [1], a simplified version of a |
| 34 // Matroska container [2], composed of an EBML header, and a single Segment | 35 // Matroska container [2], composed of an EBML header, and a single Segment |
| 35 // including at least a Track Section and a number of SimpleBlocks each | 36 // including at least a Track Section and a number of SimpleBlocks each |
| 36 // containing a single encoded video or audio frame. WebM container has no | 37 // containing a single encoded video or audio frame. WebM container has no |
| 37 // Trailer. | 38 // Trailer. |
| 38 // Clients will push encoded VPx video frames and Opus audio frames one by one | 39 // Clients will push encoded VPx video frames and Opus audio frames one by one |
| 39 // via OnEncoded{Video|Audio}(). libwebm will eventually ping the WriteDataCB | 40 // via OnEncoded{Video|Audio}(). libwebm will eventually ping the WriteDataCB |
| 40 // passed on contructor with the wrapped encoded data. | 41 // passed on contructor with the wrapped encoded data. |
| 41 // WebmMuxer is designed for use on a single thread. | 42 // WebmMuxer is designed for use on a single thread. |
| 42 // [1] http://www.webmproject.org/docs/container/ | 43 // [1] http://www.webmproject.org/docs/container/ |
| 43 // [2] http://www.matroska.org/technical/specs/index.html | 44 // [2] http://www.matroska.org/technical/specs/index.html |
| 44 class MEDIA_EXPORT WebmMuxer : public NON_EXPORTED_BASE(mkvmuxer::IMkvWriter) { | 45 class MEDIA_EXPORT WebmMuxer : public NON_EXPORTED_BASE(mkvmuxer::IMkvWriter) { |
| 45 public: | 46 public: |
| 46 // Callback to be called when WebmMuxer is ready to write a chunk of data, | 47 // Callback to be called when WebmMuxer is ready to write a chunk of data, |
| 47 // either any file header or a SingleBlock. | 48 // either any file header or a SingleBlock. |
| 48 using WriteDataCB = base::Callback<void(base::StringPiece)>; | 49 using WriteDataCB = base::Callback<void(base::StringPiece)>; |
| 49 | 50 |
| 51 // Container for the parameters that muxer uses that is extracted from |
| 52 // media::VideoFrame. |
| 53 struct MEDIA_EXPORT VideoParameters { |
| 54 VideoParameters(scoped_refptr<media::VideoFrame> frame); |
| 55 ~VideoParameters(); |
| 56 gfx::Size visible_rect_size; |
| 57 double frame_rate; |
| 58 }; |
| 59 |
| 50 // |codec| can be VP8 or VP9 and should coincide with whatever is sent in | 60 // |codec| can be VP8 or VP9 and should coincide with whatever is sent in |
| 51 // OnEncodedVideo(). | 61 // OnEncodedVideo(). |
| 52 WebmMuxer(VideoCodec codec, | 62 WebmMuxer(VideoCodec codec, |
| 53 bool has_video_, | 63 bool has_video_, |
| 54 bool has_audio_, | 64 bool has_audio_, |
| 55 const WriteDataCB& write_data_callback); | 65 const WriteDataCB& write_data_callback); |
| 56 ~WebmMuxer() override; | 66 ~WebmMuxer() override; |
| 57 | 67 |
| 58 // Functions to add video and audio frames with |encoded_data.data()| | 68 // Functions to add video and audio frames with |encoded_data.data()| |
| 59 // to WebM Segment. | 69 // to WebM Segment. |
| 60 void OnEncodedVideo(const scoped_refptr<VideoFrame>& video_frame, | 70 void OnEncodedVideo(const VideoParameters& params, |
| 61 std::unique_ptr<std::string> encoded_data, | 71 std::unique_ptr<std::string> encoded_data, |
| 62 base::TimeTicks timestamp, | 72 base::TimeTicks timestamp, |
| 63 bool is_key_frame); | 73 bool is_key_frame); |
| 64 void OnEncodedAudio(const media::AudioParameters& params, | 74 void OnEncodedAudio(const media::AudioParameters& params, |
| 65 std::unique_ptr<std::string> encoded_data, | 75 std::unique_ptr<std::string> encoded_data, |
| 66 base::TimeTicks timestamp); | 76 base::TimeTicks timestamp); |
| 67 | 77 |
| 68 void Pause(); | 78 void Pause(); |
| 69 void Resume(); | 79 void Resume(); |
| 70 | 80 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 DISALLOW_IMPLICIT_CONSTRUCTORS(EncodedVideoFrame); | 153 DISALLOW_IMPLICIT_CONSTRUCTORS(EncodedVideoFrame); |
| 144 }; | 154 }; |
| 145 std::deque<std::unique_ptr<EncodedVideoFrame>> encoded_frames_queue_; | 155 std::deque<std::unique_ptr<EncodedVideoFrame>> encoded_frames_queue_; |
| 146 | 156 |
| 147 DISALLOW_COPY_AND_ASSIGN(WebmMuxer); | 157 DISALLOW_COPY_AND_ASSIGN(WebmMuxer); |
| 148 }; | 158 }; |
| 149 | 159 |
| 150 } // namespace media | 160 } // namespace media |
| 151 | 161 |
| 152 #endif // MEDIA_MUXERS_WEBM_MUXER_H_ | 162 #endif // MEDIA_MUXERS_WEBM_MUXER_H_ |
| OLD | NEW |