Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Side by Side Diff: webrtc/modules/video_coding/codecs/vp8/vp8_sequence_coder.cc

Issue 2089773002: Add EncodedImageCallback::OnEncodedImage(). (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: . Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 int Encoded(const webrtc::EncodedImage& encoded_image, 29 Result OnEncodedImage(const webrtc::EncodedImage& encoded_image,
30 const webrtc::CodecSpecificInfo* codecSpecificInfo, 30 const webrtc::CodecSpecificInfo* codec_specific_info,
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 int Vp8SequenceCoderEncodeCallback::Encoded( 46
47 webrtc::EncodedImageCallback::Result
48 Vp8SequenceCoderEncodeCallback::OnEncodedImage(
47 const webrtc::EncodedImage& encoded_image, 49 const webrtc::EncodedImage& encoded_image,
48 const webrtc::CodecSpecificInfo* codecSpecificInfo, 50 const webrtc::CodecSpecificInfo* codecSpecificInfo,
49 const webrtc::RTPFragmentationHeader* fragmentation) { 51 const webrtc::RTPFragmentationHeader* fragmentation) {
50 if (encoded_image_._size < encoded_image._size) { 52 if (encoded_image_._size < encoded_image._size) {
51 delete[] encoded_image_._buffer; 53 delete[] encoded_image_._buffer;
52 encoded_image_._buffer = NULL; 54 encoded_image_._buffer = NULL;
53 encoded_image_._buffer = new uint8_t[encoded_image._size]; 55 encoded_image_._buffer = new uint8_t[encoded_image._size];
54 encoded_image_._size = encoded_image._size; 56 encoded_image_._size = encoded_image._size;
55 } 57 }
56 memcpy(encoded_image_._buffer, encoded_image._buffer, encoded_image._size); 58 memcpy(encoded_image_._buffer, encoded_image._buffer, encoded_image._size);
57 encoded_image_._length = encoded_image._length; 59 encoded_image_._length = encoded_image._length;
58 if (encoded_file_ != NULL) { 60 if (encoded_file_ != NULL) {
59 if (fwrite(encoded_image._buffer, 1, encoded_image._length, 61 if (fwrite(encoded_image._buffer, 1, encoded_image._length,
60 encoded_file_) != encoded_image._length) { 62 encoded_file_) != encoded_image._length) {
61 return -1; 63 return Result(Result::ERROR_SEND_FAILED, 0);
62 } 64 }
63 } 65 }
64 encoded_bytes_ += encoded_image_._length; 66 encoded_bytes_ += encoded_image_._length;
65 return 0; 67 return Result(Result::OK, 0);
66 } 68 }
67 69
68 // TODO(mikhal): Add support for varying the frame size. 70 // TODO(mikhal): Add support for varying the frame size.
69 class Vp8SequenceCoderDecodeCallback : public webrtc::DecodedImageCallback { 71 class Vp8SequenceCoderDecodeCallback : public webrtc::DecodedImageCallback {
70 public: 72 public:
71 explicit Vp8SequenceCoderDecodeCallback(FILE* decoded_file) 73 explicit Vp8SequenceCoderDecodeCallback(FILE* decoded_file)
72 : decoded_file_(decoded_file) {} 74 : decoded_file_(decoded_file) {}
73 int32_t Decoded(webrtc::VideoFrame& frame) override; 75 int32_t Decoded(webrtc::VideoFrame& frame) override;
74 int32_t Decoded(webrtc::VideoFrame& frame, int64_t decode_time_ms) override { 76 int32_t Decoded(webrtc::VideoFrame& frame, int64_t decode_time_ms) override {
75 RTC_NOTREACHED(); 77 RTC_NOTREACHED();
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 239
238 parser.ProcessFlags(); 240 parser.ProcessFlags();
239 if (parser.GetFlag("help") == "true") { 241 if (parser.GetFlag("help") == "true") {
240 parser.PrintUsageMessage(); 242 parser.PrintUsageMessage();
241 exit(EXIT_SUCCESS); 243 exit(EXIT_SUCCESS);
242 } 244 }
243 parser.PrintEnteredFlags(); 245 parser.PrintEnteredFlags();
244 246
245 return SequenceCoder(&parser); 247 return SequenceCoder(&parser);
246 } 248 }
OLDNEW
« no previous file with comments | « webrtc/modules/video_coding/codecs/vp8/test/vp8_impl_unittest.cc ('k') | webrtc/modules/video_coding/generic_encoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698