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 <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 37 class MEDIA_EXPORT WebmMuxer : public NON_EXPORTED_BASE(mkvmuxer::IMkvWriter) { | 37 class MEDIA_EXPORT WebmMuxer : public NON_EXPORTED_BASE(mkvmuxer::IMkvWriter) { |
| 38 public: | 38 public: |
| 39 // 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, |
| 40 // either any file header or a SingleBlock. | 40 // either any file header or a SingleBlock. |
| 41 using WriteDataCB = base::Callback<void(base::StringPiece)>; | 41 using WriteDataCB = base::Callback<void(base::StringPiece)>; |
| 42 | 42 |
| 43 explicit WebmMuxer(const WriteDataCB& write_data_callback); | 43 explicit WebmMuxer(const WriteDataCB& write_data_callback); |
| 44 ~WebmMuxer() override; | 44 ~WebmMuxer() override; |
| 45 | 45 |
| 46 // Adds a |video_frame| with |encoded_data.data()| to WebM Segment. | 46 // Adds a |video_frame| with |encoded_data.data()| to WebM Segment. |
| 47 void OnEncodedVideo(const scoped_refptr<VideoFrame>& video_frame, | 47 void OnEncodedVideo(int track_index, |
| 48 const scoped_refptr<VideoFrame>& video_frame, | |
| 48 scoped_ptr<std::string> encoded_data, | 49 scoped_ptr<std::string> encoded_data, |
| 49 base::TimeTicks timestamp, | 50 base::TimeTicks timestamp, |
| 50 bool is_key_frame); | 51 bool is_key_frame); |
| 51 | 52 |
| 53 int GetNextVideoTrackIndex(); | |
|
mcasas
2015/10/06 17:53:13
Should be const.
Actually it shouldn't exist at a
msu.koo
2015/10/07 04:52:19
Cool way! Thank you for your advice. reflected.
| |
| 54 | |
| 52 private: | 55 private: |
| 53 friend class WebmMuxerTest; | 56 friend class WebmMuxerTest; |
| 57 struct VideoMuxerArg { | |
| 58 VideoMuxerArg( | |
| 59 const base::TimeTicks& first_frame_timestamp, uint64 track_number) | |
| 60 : first_frame_timestamp(first_frame_timestamp), | |
| 61 track_number(track_number) {} | |
| 62 | |
| 63 base::TimeTicks first_frame_timestamp; | |
| 64 uint64 track_number; | |
| 65 }; | |
| 54 | 66 |
| 55 // Creates and adds a new video track. Called upon receiving the first | 67 // Creates and adds a new video track. Called upon receiving the first |
| 56 // frame of a given Track, adds |frame_size| and |frame_rate| to the Segment | 68 // frame of a given Track, adds |frame_size| and |frame_rate| to the Segment |
| 57 // info, although individual frames passed to OnEncodedVideo() can have any | 69 // info, although individual frames passed to OnEncodedVideo() can have any |
| 58 // frame size. | 70 // frame size. |
| 59 void AddVideoTrack(const gfx::Size& frame_size, double frame_rate); | 71 uint64 AddVideoTrack(const gfx::Size& frame_size, double frame_rate); |
| 60 | 72 |
| 61 // IMkvWriter interface. | 73 // IMkvWriter interface. |
| 62 mkvmuxer::int32 Write(const void* buf, mkvmuxer::uint32 len) override; | 74 mkvmuxer::int32 Write(const void* buf, mkvmuxer::uint32 len) override; |
| 63 mkvmuxer::int64 Position() const override; | 75 mkvmuxer::int64 Position() const override; |
| 64 mkvmuxer::int32 Position(mkvmuxer::int64 position) override; | 76 mkvmuxer::int32 Position(mkvmuxer::int64 position) override; |
| 65 bool Seekable() const override; | 77 bool Seekable() const override; |
| 66 void ElementStartNotify(mkvmuxer::uint64 element_id, | 78 void ElementStartNotify(mkvmuxer::uint64 element_id, |
| 67 mkvmuxer::int64 position) override; | 79 mkvmuxer::int64 position) override; |
| 68 | 80 |
| 69 // Used to DCHECK that we are called on the correct thread. | 81 // Used to DCHECK that we are called on the correct thread. |
| 70 base::ThreadChecker thread_checker_; | 82 base::ThreadChecker thread_checker_; |
| 71 | 83 |
| 72 // A caller-side identifier to interact with |segment_|, initialised upon | 84 // Arguments for each tracks to mkvmuxer. |
| 73 // first frame arrival by AddVideoTrack(). | 85 std::vector<VideoMuxerArg> video_muxer_args_; |
|
mcasas
2015/10/06 17:53:13
What about a std::map indexed by track indexes?
msu.koo
2015/10/07 04:52:19
I considered to use Map for this, but using vector
| |
| 74 uint64_t track_index_; | |
| 75 | |
| 76 // Origin of times for frame timestamps. | |
| 77 base::TimeTicks first_frame_timestamp_; | |
| 78 | 86 |
| 79 // Callback to dump written data as being called by libwebm. | 87 // Callback to dump written data as being called by libwebm. |
| 80 const WriteDataCB write_data_callback_; | 88 const WriteDataCB write_data_callback_; |
| 81 | 89 |
| 82 // Rolling counter of the position in bytes of the written goo. | 90 // Rolling counter of the position in bytes of the written goo. |
| 83 base::CheckedNumeric<mkvmuxer::int64> position_; | 91 base::CheckedNumeric<mkvmuxer::int64> position_; |
| 84 | 92 |
| 85 // The MkvMuxer active element. | 93 // The MkvMuxer active element. |
| 86 mkvmuxer::Segment segment_; | 94 mkvmuxer::Segment segment_; |
| 87 | 95 |
| 88 DISALLOW_COPY_AND_ASSIGN(WebmMuxer); | 96 DISALLOW_COPY_AND_ASSIGN(WebmMuxer); |
| 89 }; | 97 }; |
| 90 | 98 |
| 91 } // namespace media | 99 } // namespace media |
| 92 | 100 |
| 93 #endif // MEDIA_FILTERS_LIBWEBM_MUXER_H_ | 101 #endif // MEDIA_FILTERS_LIBWEBM_MUXER_H_ |
| OLD | NEW |