Remove INJECT_EVENTS permissions from test APKs.
[chromium-blink-merge.git] / media / cast / sender / fake_software_video_encoder.cc
blob53cfb6c1e4d95db639a44c6a78f7c8e9fa0aed63
1 // Copyright 2014 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.
5 #include "media/cast/sender/fake_software_video_encoder.h"
7 #include "base/json/json_writer.h"
8 #include "base/values.h"
9 #include "media/base/video_frame.h"
11 #ifndef OFFICIAL_BUILD
13 namespace media {
14 namespace cast {
16 FakeSoftwareVideoEncoder::FakeSoftwareVideoEncoder(
17 const VideoSenderConfig& video_config)
18 : video_config_(video_config),
19 next_frame_is_key_(true),
20 frame_id_(0),
21 frame_id_to_reference_(0),
22 frame_size_(0) {
25 FakeSoftwareVideoEncoder::~FakeSoftwareVideoEncoder() {}
27 void FakeSoftwareVideoEncoder::Initialize() {}
29 void FakeSoftwareVideoEncoder::Encode(
30 const scoped_refptr<media::VideoFrame>& video_frame,
31 const base::TimeTicks& reference_time,
32 SenderEncodedFrame* encoded_frame) {
33 DCHECK(encoded_frame);
35 if (video_frame->visible_rect().size() != last_frame_size_) {
36 next_frame_is_key_ = true;
37 last_frame_size_ = video_frame->visible_rect().size();
40 encoded_frame->frame_id = frame_id_++;
41 if (next_frame_is_key_) {
42 encoded_frame->dependency = EncodedFrame::KEY;
43 encoded_frame->referenced_frame_id = encoded_frame->frame_id;
44 next_frame_is_key_ = false;
45 } else {
46 encoded_frame->dependency = EncodedFrame::DEPENDENT;
47 encoded_frame->referenced_frame_id = encoded_frame->frame_id - 1;
49 encoded_frame->rtp_timestamp =
50 TimeDeltaToRtpDelta(video_frame->timestamp(), kVideoFrequency);
51 encoded_frame->reference_time = reference_time;
53 base::DictionaryValue values;
54 values.SetBoolean("key",
55 encoded_frame->dependency == EncodedFrame::KEY);
56 values.SetInteger("ref", encoded_frame->referenced_frame_id);
57 values.SetInteger("id", encoded_frame->frame_id);
58 values.SetInteger("size", frame_size_);
59 base::JSONWriter::Write(values, &encoded_frame->data);
60 encoded_frame->data.resize(
61 std::max<size_t>(encoded_frame->data.size(), frame_size_), ' ');
63 if (encoded_frame->dependency == EncodedFrame::KEY) {
64 encoded_frame->deadline_utilization = 1.0;
65 encoded_frame->lossy_utilization = 6.0;
66 } else {
67 encoded_frame->deadline_utilization = 0.8;
68 encoded_frame->lossy_utilization = 0.8;
72 void FakeSoftwareVideoEncoder::UpdateRates(uint32 new_bitrate) {
73 frame_size_ = new_bitrate / video_config_.max_frame_rate / 8;
76 void FakeSoftwareVideoEncoder::GenerateKeyFrame() {
77 next_frame_is_key_ = true;
80 void FakeSoftwareVideoEncoder::LatestFrameIdToReference(uint32 frame_id) {
81 frame_id_to_reference_ = frame_id;
84 } // namespace cast
85 } // namespace media
87 #endif