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

Side by Side Diff: third_party/openh264/testing/h264_codec_tester.cc

Issue 1446453004: Adding third_party/openh264 build files for encoding (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase with master Created 5 years, 1 month 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "third_party/openh264/testing/h264_codec_tester.h"
6
7 using namespace webrtc;
8
9 namespace openh264 {
10
11 H264CodecTester::H264CodecTester() : last_encoded_image_(nullptr),
12 last_decoded_image_(nullptr) {
13 }
14
15 H264CodecTester::~H264CodecTester() {
16 encoder_.Release();
17 decoder_.Release();
18 }
19
20 bool H264CodecTester::Init(unsigned short width, unsigned short height) {
21 const int32_t number_of_cores = 1;
22 const size_t max_payload_size = 0;
23
24 // Codec settings...
25 VideoCodec codec;
26 memset(&codec, 0, sizeof(codec));
27
28 codec.codecType = kVideoCodecH264;
29 strncpy(codec.plName, "H264", 5);
30 codec.plType = 120;
31
32 codec.width = width;
33 codec.height = height;
34
35 codec.minBitrate = 300;
36 codec.maxBitrate = 600;
37 codec.targetBitrate = 450;
38 codec.startBitrate = codec.minBitrate;
39 codec.maxFramerate = 30;
40
41 memset(&codec.codecSpecific.H264, 0, sizeof(codec.codecSpecific.H264));
42 codec.codecSpecific.H264.profile = kProfileBase;
43 codec.codecSpecific.H264.frameDroppingOn = true;
44 codec.codecSpecific.H264.keyFrameInterval = 3000;
45 codec.codecSpecific.H264.spsData = nullptr;
46 codec.codecSpecific.H264.spsLen = 0;
47 codec.codecSpecific.H264.ppsData = nullptr;
48 codec.codecSpecific.H264.ppsLen = 0;
49
50 codec.qpMax = 56;
51 codec.numberOfSimulcastStreams = 1;
52 codec.simulcastStream[0].width = codec.width;
53 codec.simulcastStream[0].height = codec.height;
54 codec.simulcastStream[0].minBitrate = codec.minBitrate;
55 codec.simulcastStream[0].maxBitrate = codec.maxBitrate;
56 codec.simulcastStream[0].targetBitrate = codec.targetBitrate;
57 codec.simulcastStream[0].qpMax = codec.qpMax;
58 codec.simulcastStream[0].numberOfTemporalLayers = 1;
59
60 codec.mode = kRealtimeVideo;
61 codec.extra_options = nullptr;
62
63 // Initialize encoder and decoder.
64 if (encoder_.InitEncode(&codec, number_of_cores, max_payload_size)
65 != WEBRTC_VIDEO_CODEC_OK) {
66 encoder_.Release();
67 return false;
68 }
69 if (decoder_.InitDecode(&codec, number_of_cores) != WEBRTC_VIDEO_CODEC_OK) {
70 encoder_.Release();
71 decoder_.Release();
72 return false;
73 }
74
75 // Register so that Encoded and Decoded will be called.
76 encoder_.RegisterEncodeCompleteCallback(this);
77 decoder_.RegisterDecodeCompleteCallback(this);
78
79 return true;
80 }
81
82 bool H264CodecTester::Encode(const VideoFrame& frame) {
83 last_encoded_image_ = nullptr;
84 if (encoder_.Encode(frame, nullptr, nullptr) != WEBRTC_VIDEO_CODEC_OK ||
85 !last_encoded_image_) {
86 return false;
87 }
88 return true;
89 }
90
91 VideoFrame* H264CodecTester::Decode() {
92 last_decoded_image_ = nullptr;
93 if (decoder_.Decode(*last_encoded_image_, false, nullptr)
94 != WEBRTC_VIDEO_CODEC_OK || !last_decoded_image_) {
95 return nullptr;
96 }
97 return last_decoded_image_;
98 }
99
100 int32_t H264CodecTester::Encoded(const EncodedImage& encoded_image,
101 const CodecSpecificInfo* codec_specific_info,
102 const RTPFragmentationHeader* fragmentation) {
103 last_encoded_image_ = &encoded_image;
104 return WEBRTC_VIDEO_CODEC_OK;
105 }
106
107 int32_t H264CodecTester::Decoded(VideoFrame& decoded_image) {
108 last_decoded_image_ = &decoded_image;
109 return WEBRTC_VIDEO_CODEC_OK;
110 }
111
112 } // namespace openh264
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698