| 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 #include "base/bind.h" | 5 #include "base/bind.h" | 
| 6 #include "base/location.h" | 6 #include "base/location.h" | 
| 7 #include "base/macros.h" | 7 #include "base/macros.h" | 
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" | 
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" | 
| 10 #include "media/base/video_frame.h" | 10 #include "media/base/video_frame.h" | 
| (...skipping 16 matching lines...) Expand all  Loading... | 
| 27 }; | 27 }; | 
| 28 | 28 | 
| 29 class WebmMuxerTest : public testing::Test, public EventHandlerInterface { | 29 class WebmMuxerTest : public testing::Test, public EventHandlerInterface { | 
| 30  public: | 30  public: | 
| 31   WebmMuxerTest() | 31   WebmMuxerTest() | 
| 32       : webm_muxer_(base::Bind(&WebmMuxerTest::WriteCallback, | 32       : webm_muxer_(base::Bind(&WebmMuxerTest::WriteCallback, | 
| 33                                base::Unretained(this))), | 33                                base::Unretained(this))), | 
| 34         last_encoded_length_(0), | 34         last_encoded_length_(0), | 
| 35         accumulated_position_(0) { | 35         accumulated_position_(0) { | 
| 36     EXPECT_EQ(webm_muxer_.Position(), 0); | 36     EXPECT_EQ(webm_muxer_.Position(), 0); | 
|  | 37     const mkvmuxer::int64 kRandomNewPosition = 333; | 
|  | 38     EXPECT_EQ(webm_muxer_.Position(kRandomNewPosition), -1); | 
| 37     EXPECT_FALSE(webm_muxer_.Seekable()); | 39     EXPECT_FALSE(webm_muxer_.Seekable()); | 
| 38     EXPECT_EQ(webm_muxer_.segment_.mode(), mkvmuxer::Segment::kLive); |  | 
| 39   } | 40   } | 
| 40 | 41 | 
| 41   MOCK_METHOD1(WriteCallback, void(const base::StringPiece&)); | 42   MOCK_METHOD1(WriteCallback, void(const base::StringPiece&)); | 
| 42 | 43 | 
| 43   void SaveEncodedDataLen(const base::StringPiece& encoded_data) { | 44   void SaveEncodedDataLen(const base::StringPiece& encoded_data) { | 
| 44     last_encoded_length_ = encoded_data.size(); | 45     last_encoded_length_ = encoded_data.size(); | 
| 45     accumulated_position_ += encoded_data.size(); | 46     accumulated_position_ += encoded_data.size(); | 
| 46   } | 47   } | 
| 47 | 48 | 
| 48   mkvmuxer::int64 GetWebmMuxerPosition() const { | 49   mkvmuxer::int64 GetWebmMuxerPosition() const { | 
| 49     return webm_muxer_.Position(); | 50     return webm_muxer_.Position(); | 
| 50   } | 51   } | 
| 51 | 52 | 
|  | 53   mkvmuxer::Segment::Mode GetWebmSegmentMode() const { | 
|  | 54     return webm_muxer_.segment_.mode(); | 
|  | 55   } | 
|  | 56 | 
| 52   mkvmuxer::int32 WebmMuxerWrite(const void* buf, mkvmuxer::uint32 len) { | 57   mkvmuxer::int32 WebmMuxerWrite(const void* buf, mkvmuxer::uint32 len) { | 
| 53     return webm_muxer_.Write(buf, len); | 58     return webm_muxer_.Write(buf, len); | 
| 54   } | 59   } | 
| 55 | 60 | 
| 56   WebmMuxer webm_muxer_; | 61   WebmMuxer webm_muxer_; | 
| 57 | 62 | 
| 58   size_t last_encoded_length_; | 63   size_t last_encoded_length_; | 
| 59   int64_t accumulated_position_; | 64   int64_t accumulated_position_; | 
| 60 | 65 | 
| 61  private: | 66  private: | 
| (...skipping 26 matching lines...) Expand all  Loading... | 
| 88   webm_muxer_.OnEncodedVideo(video_frame, | 93   webm_muxer_.OnEncodedVideo(video_frame, | 
| 89                              encoded_data, | 94                              encoded_data, | 
| 90                              base::TimeTicks::Now(), | 95                              base::TimeTicks::Now(), | 
| 91                              false  /* keyframe */); | 96                              false  /* keyframe */); | 
| 92 | 97 | 
| 93   // First time around WriteCallback() is pinged a number of times to write the | 98   // First time around WriteCallback() is pinged a number of times to write the | 
| 94   // Matroska header, but at the end it dumps |encoded_data|. | 99   // Matroska header, but at the end it dumps |encoded_data|. | 
| 95   EXPECT_EQ(last_encoded_length_, encoded_data.size()); | 100   EXPECT_EQ(last_encoded_length_, encoded_data.size()); | 
| 96   EXPECT_EQ(GetWebmMuxerPosition(), accumulated_position_); | 101   EXPECT_EQ(GetWebmMuxerPosition(), accumulated_position_); | 
| 97   EXPECT_GE(GetWebmMuxerPosition(), static_cast<int64_t>(last_encoded_length_)); | 102   EXPECT_GE(GetWebmMuxerPosition(), static_cast<int64_t>(last_encoded_length_)); | 
|  | 103   EXPECT_EQ(GetWebmSegmentMode(), mkvmuxer::Segment::kLive); | 
| 98 | 104 | 
| 99   const int64_t begin_of_second_block = accumulated_position_; | 105   const int64_t begin_of_second_block = accumulated_position_; | 
| 100   EXPECT_CALL(*this, WriteCallback(_)) | 106   EXPECT_CALL(*this, WriteCallback(_)) | 
| 101       .Times(AtLeast(1)) | 107       .Times(AtLeast(1)) | 
| 102       .WillRepeatedly(WithArgs<0>( | 108       .WillRepeatedly(WithArgs<0>( | 
| 103           Invoke(this, &WebmMuxerTest::SaveEncodedDataLen))); | 109           Invoke(this, &WebmMuxerTest::SaveEncodedDataLen))); | 
| 104   webm_muxer_.OnEncodedVideo(video_frame, | 110   webm_muxer_.OnEncodedVideo(video_frame, | 
| 105                              encoded_data, | 111                              encoded_data, | 
| 106                              base::TimeTicks::Now(), | 112                              base::TimeTicks::Now(), | 
| 107                              false  /* keyframe */); | 113                              false  /* keyframe */); | 
| 108 | 114 | 
| 109   // The second time around the callbacks should include a SimpleBlock header, | 115   // The second time around the callbacks should include a SimpleBlock header, | 
| 110   // namely the track index, a timestamp and a flags byte, for a total of 6B. | 116   // namely the track index, a timestamp and a flags byte, for a total of 6B. | 
| 111   EXPECT_EQ(last_encoded_length_, encoded_data.size()); | 117   EXPECT_EQ(last_encoded_length_, encoded_data.size()); | 
| 112   EXPECT_EQ(GetWebmMuxerPosition(), accumulated_position_); | 118   EXPECT_EQ(GetWebmMuxerPosition(), accumulated_position_); | 
| 113   const uint32_t kSimpleBlockSize = 6u; | 119   const uint32_t kSimpleBlockSize = 6u; | 
| 114   EXPECT_EQ(static_cast<int64_t>(begin_of_second_block + kSimpleBlockSize + | 120   EXPECT_EQ(static_cast<int64_t>(begin_of_second_block + kSimpleBlockSize + | 
| 115                                  encoded_data.size()), | 121                                  encoded_data.size()), | 
| 116             accumulated_position_); | 122             accumulated_position_); | 
| 117 } | 123 } | 
| 118 | 124 | 
| 119 }  // namespace media | 125 }  // namespace media | 
| OLD | NEW | 
|---|