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

Side by Side Diff: media/cast/video_sender/video_encoder.cc

Issue 74133002: Cast: Removed unnecessary ref counters. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changed to lock form atomic int Created 7 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "media/cast/video_sender/video_encoder.h" 5 #include "media/cast/video_sender/video_encoder.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop/message_loop.h"
9 10
10 namespace media { 11 namespace media {
11 namespace cast { 12 namespace cast {
12 13
13 VideoEncoder::VideoEncoder(scoped_refptr<CastEnvironment> cast_environment, 14 VideoEncoder::VideoEncoder(scoped_refptr<CastEnvironment> cast_environment,
14 const VideoSenderConfig& video_config, 15 const VideoSenderConfig& video_config,
15 uint8 max_unacked_frames) 16 uint8 max_unacked_frames)
16 : video_config_(video_config), 17 : video_config_(video_config),
17 cast_environment_(cast_environment), 18 cast_environment_(cast_environment),
18 skip_next_frame_(false), 19 skip_next_frame_(false),
19 skip_count_(0) { 20 skip_count_(0),
21 weak_factory_(this) {
20 if (video_config.codec == kVp8) { 22 if (video_config.codec == kVp8) {
21 vp8_encoder_.reset(new Vp8Encoder(video_config, max_unacked_frames)); 23 vp8_encoder_.reset(new Vp8Encoder(video_config, max_unacked_frames));
22 } else { 24 } else {
23 DCHECK(false) << "Invalid config"; // Codec not supported. 25 DCHECK(false) << "Invalid config"; // Codec not supported.
24 } 26 }
25 27
26 dynamic_config_.key_frame_requested = false; 28 dynamic_config_.key_frame_requested = false;
27 dynamic_config_.latest_frame_id_to_reference = kStartFrameId; 29 dynamic_config_.latest_frame_id_to_reference = kStartFrameId;
28 dynamic_config_.bit_rate = video_config.start_bitrate; 30 dynamic_config_.bit_rate = video_config.start_bitrate;
29 } 31 }
30 32
31 VideoEncoder::~VideoEncoder() {} 33 VideoEncoder::~VideoEncoder() {}
32 34
33 bool VideoEncoder::EncodeVideoFrame( 35 bool VideoEncoder::EncodeVideoFrame(
34 const I420VideoFrame* video_frame, 36 const I420VideoFrame* video_frame,
35 const base::TimeTicks& capture_time, 37 const base::TimeTicks& capture_time,
36 const FrameEncodedCallback& frame_encoded_callback, 38 const FrameEncodedCallback& frame_encoded_callback,
37 const base::Closure frame_release_callback) { 39 const base::Closure frame_release_callback) {
40 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
38 if (video_config_.codec != kVp8) return false; 41 if (video_config_.codec != kVp8) return false;
39 42
40 if (skip_next_frame_) { 43 if (skip_next_frame_) {
41 ++skip_count_; 44 ++skip_count_;
42 VLOG(1) << "Skip encoding frame"; 45 VLOG(1) << "Skip encoding frame";
43 return false; 46 return false;
44 } 47 }
45 48
46 cast_environment_->PostTask(CastEnvironment::VIDEO_ENCODER, FROM_HERE, 49 cast_environment_->PostTask(CastEnvironment::VIDEO_ENCODER, FROM_HERE,
47 base::Bind(&VideoEncoder::EncodeVideoFrameEncoderThread, this, 50 base::Bind(&VideoEncoder::EncodeVideoFrameEncoderThread,
48 video_frame, capture_time, dynamic_config_, frame_encoded_callback, 51 weak_factory_.GetWeakPtr(), video_frame, capture_time,
49 frame_release_callback)); 52 dynamic_config_, frame_encoded_callback, frame_release_callback));
50 53
51 dynamic_config_.key_frame_requested = false; 54 dynamic_config_.key_frame_requested = false;
52 return true; 55 return true;
53 } 56 }
54 57
55 void VideoEncoder::EncodeVideoFrameEncoderThread( 58 void VideoEncoder::EncodeVideoFrameEncoderThread(
56 const I420VideoFrame* video_frame, 59 const I420VideoFrame* video_frame,
57 const base::TimeTicks& capture_time, 60 const base::TimeTicks& capture_time,
58 const CodecDynamicConfig& dynamic_config, 61 const CodecDynamicConfig& dynamic_config,
59 const FrameEncodedCallback& frame_encoded_callback, 62 const FrameEncodedCallback& frame_encoded_callback,
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 void VideoEncoder::LatestFrameIdToReference(uint8 frame_id) { 107 void VideoEncoder::LatestFrameIdToReference(uint8 frame_id) {
105 dynamic_config_.latest_frame_id_to_reference = frame_id; 108 dynamic_config_.latest_frame_id_to_reference = frame_id;
106 } 109 }
107 110
108 int VideoEncoder::NumberOfSkippedFrames() const { 111 int VideoEncoder::NumberOfSkippedFrames() const {
109 return skip_count_; 112 return skip_count_;
110 } 113 }
111 114
112 } // namespace cast 115 } // namespace cast
113 } // namespace media 116 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698