| OLD | NEW | 
|---|
| 1 /* | 1 /* | 
| 2  *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2  *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 
| 3  * | 3  * | 
| 4  *  Use of this source code is governed by a BSD-style license | 4  *  Use of this source code is governed by a BSD-style license | 
| 5  *  that can be found in the LICENSE file in the root of the source | 5  *  that can be found in the LICENSE file in the root of the source | 
| 6  *  tree. An additional intellectual property rights grant can be found | 6  *  tree. An additional intellectual property rights grant can be found | 
| 7  *  in the file PATENTS.  All contributing project authors may | 7  *  in the file PATENTS.  All contributing project authors may | 
| 8  *  be found in the AUTHORS file in the root of the source tree. | 8  *  be found in the AUTHORS file in the root of the source tree. | 
| 9  */ | 9  */ | 
| 10 | 10 | 
| 11 #include <memory> | 11 #include <memory> | 
| 12 | 12 | 
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" | 
| 14 #include "webrtc/base/checks.h" | 14 #include "webrtc/base/checks.h" | 
| 15 #include "webrtc/base/timeutils.h" | 15 #include "webrtc/base/timeutils.h" | 
| 16 #include "webrtc/common_video/include/video_image.h" | 16 #include "webrtc/common_video/include/video_image.h" | 
| 17 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" | 17 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" | 
| 18 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h" | 18 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h" | 
| 19 #include "webrtc/test/testsupport/fileutils.h" | 19 #include "webrtc/test/testsupport/fileutils.h" | 
| 20 #include "webrtc/test/testsupport/metrics/video_metrics.h" | 20 #include "webrtc/test/testsupport/metrics/video_metrics.h" | 
| 21 #include "webrtc/tools/simple_command_line_parser.h" | 21 #include "webrtc/tools/simple_command_line_parser.h" | 
| 22 #include "webrtc/video_frame.h" | 22 #include "webrtc/video_frame.h" | 
| 23 | 23 | 
| 24 class Vp8SequenceCoderEncodeCallback : public webrtc::EncodedImageCallback { | 24 class Vp8SequenceCoderEncodeCallback : public webrtc::EncodedImageCallback { | 
| 25  public: | 25  public: | 
| 26   explicit Vp8SequenceCoderEncodeCallback(FILE* encoded_file) | 26   explicit Vp8SequenceCoderEncodeCallback(FILE* encoded_file) | 
| 27       : encoded_file_(encoded_file), encoded_bytes_(0) {} | 27       : encoded_file_(encoded_file), encoded_bytes_(0) {} | 
| 28   ~Vp8SequenceCoderEncodeCallback(); | 28   ~Vp8SequenceCoderEncodeCallback(); | 
| 29   Result OnEncodedImage(const webrtc::EncodedImage& encoded_image, | 29   int Encoded(const webrtc::EncodedImage& encoded_image, | 
| 30                         const webrtc::CodecSpecificInfo* codec_specific_info, | 30               const webrtc::CodecSpecificInfo* codecSpecificInfo, | 
| 31                         const webrtc::RTPFragmentationHeader*); | 31               const webrtc::RTPFragmentationHeader*); | 
| 32   // Returns the encoded image. | 32   // Returns the encoded image. | 
| 33   webrtc::EncodedImage encoded_image() { return encoded_image_; } | 33   webrtc::EncodedImage encoded_image() { return encoded_image_; } | 
| 34   size_t encoded_bytes() { return encoded_bytes_; } | 34   size_t encoded_bytes() { return encoded_bytes_; } | 
| 35 | 35 | 
| 36  private: | 36  private: | 
| 37   webrtc::EncodedImage encoded_image_; | 37   webrtc::EncodedImage encoded_image_; | 
| 38   FILE* encoded_file_; | 38   FILE* encoded_file_; | 
| 39   size_t encoded_bytes_; | 39   size_t encoded_bytes_; | 
| 40 }; | 40 }; | 
| 41 | 41 | 
| 42 Vp8SequenceCoderEncodeCallback::~Vp8SequenceCoderEncodeCallback() { | 42 Vp8SequenceCoderEncodeCallback::~Vp8SequenceCoderEncodeCallback() { | 
| 43   delete[] encoded_image_._buffer; | 43   delete[] encoded_image_._buffer; | 
| 44   encoded_image_._buffer = NULL; | 44   encoded_image_._buffer = NULL; | 
| 45 } | 45 } | 
| 46 | 46 int Vp8SequenceCoderEncodeCallback::Encoded( | 
| 47 webrtc::EncodedImageCallback::Result |  | 
| 48 Vp8SequenceCoderEncodeCallback::OnEncodedImage( |  | 
| 49     const webrtc::EncodedImage& encoded_image, | 47     const webrtc::EncodedImage& encoded_image, | 
| 50     const webrtc::CodecSpecificInfo* codecSpecificInfo, | 48     const webrtc::CodecSpecificInfo* codecSpecificInfo, | 
| 51     const webrtc::RTPFragmentationHeader* fragmentation) { | 49     const webrtc::RTPFragmentationHeader* fragmentation) { | 
| 52   if (encoded_image_._size < encoded_image._size) { | 50   if (encoded_image_._size < encoded_image._size) { | 
| 53     delete[] encoded_image_._buffer; | 51     delete[] encoded_image_._buffer; | 
| 54     encoded_image_._buffer = NULL; | 52     encoded_image_._buffer = NULL; | 
| 55     encoded_image_._buffer = new uint8_t[encoded_image._size]; | 53     encoded_image_._buffer = new uint8_t[encoded_image._size]; | 
| 56     encoded_image_._size = encoded_image._size; | 54     encoded_image_._size = encoded_image._size; | 
| 57   } | 55   } | 
| 58   memcpy(encoded_image_._buffer, encoded_image._buffer, encoded_image._size); | 56   memcpy(encoded_image_._buffer, encoded_image._buffer, encoded_image._size); | 
| 59   encoded_image_._length = encoded_image._length; | 57   encoded_image_._length = encoded_image._length; | 
| 60   if (encoded_file_ != NULL) { | 58   if (encoded_file_ != NULL) { | 
| 61     if (fwrite(encoded_image._buffer, 1, encoded_image._length, | 59     if (fwrite(encoded_image._buffer, 1, encoded_image._length, | 
| 62                encoded_file_) != encoded_image._length) { | 60                encoded_file_) != encoded_image._length) { | 
| 63       return Result(Result::ERROR_SEND_FAILED, 0); | 61       return -1; | 
| 64     } | 62     } | 
| 65   } | 63   } | 
| 66   encoded_bytes_ += encoded_image_._length; | 64   encoded_bytes_ += encoded_image_._length; | 
| 67   return Result(Result::OK, 0); | 65   return 0; | 
| 68 } | 66 } | 
| 69 | 67 | 
| 70 // TODO(mikhal): Add support for varying the frame size. | 68 // TODO(mikhal): Add support for varying the frame size. | 
| 71 class Vp8SequenceCoderDecodeCallback : public webrtc::DecodedImageCallback { | 69 class Vp8SequenceCoderDecodeCallback : public webrtc::DecodedImageCallback { | 
| 72  public: | 70  public: | 
| 73   explicit Vp8SequenceCoderDecodeCallback(FILE* decoded_file) | 71   explicit Vp8SequenceCoderDecodeCallback(FILE* decoded_file) | 
| 74       : decoded_file_(decoded_file) {} | 72       : decoded_file_(decoded_file) {} | 
| 75   int32_t Decoded(webrtc::VideoFrame& frame) override; | 73   int32_t Decoded(webrtc::VideoFrame& frame) override; | 
| 76   int32_t Decoded(webrtc::VideoFrame& frame, int64_t decode_time_ms) override { | 74   int32_t Decoded(webrtc::VideoFrame& frame, int64_t decode_time_ms) override { | 
| 77     RTC_NOTREACHED(); | 75     RTC_NOTREACHED(); | 
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 239 | 237 | 
| 240   parser.ProcessFlags(); | 238   parser.ProcessFlags(); | 
| 241   if (parser.GetFlag("help") == "true") { | 239   if (parser.GetFlag("help") == "true") { | 
| 242     parser.PrintUsageMessage(); | 240     parser.PrintUsageMessage(); | 
| 243     exit(EXIT_SUCCESS); | 241     exit(EXIT_SUCCESS); | 
| 244   } | 242   } | 
| 245   parser.PrintEnteredFlags(); | 243   parser.PrintEnteredFlags(); | 
| 246 | 244 | 
| 247   return SequenceCoder(&parser); | 245   return SequenceCoder(&parser); | 
| 248 } | 246 } | 
| OLD | NEW | 
|---|