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

Side by Side Diff: media/cast/sender/external_video_encoder.cc

Issue 1515433002: Replace uses of raw uint32's with a type-checked RtpTimeTicks data type. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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 2014 The Chromium Authors. All rights reserved. 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 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/sender/external_video_encoder.h" 5 #include "media/cast/sender/external_video_encoder.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/debug/crash_logging.h" 10 #include "base/debug/crash_logging.h"
11 #include "base/debug/dump_without_crashing.h" 11 #include "base/debug/dump_without_crashing.h"
12 #include "base/format_macros.h" 12 #include "base/format_macros.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/memory/scoped_vector.h" 14 #include "base/memory/scoped_vector.h"
15 #include "base/memory/shared_memory.h" 15 #include "base/memory/shared_memory.h"
16 #include "base/message_loop/message_loop.h" 16 #include "base/message_loop/message_loop.h"
17 #include "base/metrics/histogram.h" 17 #include "base/metrics/histogram.h"
18 #include "base/strings/stringprintf.h" 18 #include "base/strings/stringprintf.h"
19 #include "media/base/video_frame.h" 19 #include "media/base/video_frame.h"
20 #include "media/base/video_types.h" 20 #include "media/base/video_types.h"
21 #include "media/base/video_util.h" 21 #include "media/base/video_util.h"
22 #include "media/cast/cast_config.h" 22 #include "media/cast/cast_config.h"
23 #include "media/cast/cast_defines.h" 23 #include "media/cast/cast_defines.h"
24 #include "media/cast/common/rtp_time.h"
24 #include "media/cast/logging/logging_defines.h" 25 #include "media/cast/logging/logging_defines.h"
25 #include "media/cast/net/cast_transport_config.h" 26 #include "media/cast/net/cast_transport_config.h"
26 #include "media/cast/sender/vp8_quantizer_parser.h" 27 #include "media/cast/sender/vp8_quantizer_parser.h"
27 #include "media/filters/h264_parser.h" 28 #include "media/filters/h264_parser.h"
28 29
29 namespace { 30 namespace {
30 31
31 enum { MAX_H264_QUANTIZER = 51 }; 32 enum { MAX_H264_QUANTIZER = 51 };
32 static const size_t kOutputBufferCount = 3; 33 static const size_t kOutputBufferCount = 3;
33 34
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 const InProgressFrameEncode& request = in_progress_frame_encodes_.front(); 221 const InProgressFrameEncode& request = in_progress_frame_encodes_.front();
221 222
222 scoped_ptr<SenderEncodedFrame> encoded_frame(new SenderEncodedFrame()); 223 scoped_ptr<SenderEncodedFrame> encoded_frame(new SenderEncodedFrame());
223 encoded_frame->dependency = key_frame ? EncodedFrame::KEY : 224 encoded_frame->dependency = key_frame ? EncodedFrame::KEY :
224 EncodedFrame::DEPENDENT; 225 EncodedFrame::DEPENDENT;
225 encoded_frame->frame_id = next_frame_id_++; 226 encoded_frame->frame_id = next_frame_id_++;
226 if (key_frame) 227 if (key_frame)
227 encoded_frame->referenced_frame_id = encoded_frame->frame_id; 228 encoded_frame->referenced_frame_id = encoded_frame->frame_id;
228 else 229 else
229 encoded_frame->referenced_frame_id = encoded_frame->frame_id - 1; 230 encoded_frame->referenced_frame_id = encoded_frame->frame_id - 1;
230 encoded_frame->rtp_timestamp = TimeDeltaToRtpDelta( 231 encoded_frame->rtp_timestamp = RtpTimeTicks::FromTimeDelta(
231 request.video_frame->timestamp(), kVideoFrequency); 232 request.video_frame->timestamp(), kVideoFrequency);
232 encoded_frame->reference_time = request.reference_time; 233 encoded_frame->reference_time = request.reference_time;
233 if (!stream_header_.empty()) { 234 if (!stream_header_.empty()) {
234 encoded_frame->data = stream_header_; 235 encoded_frame->data = stream_header_;
235 stream_header_.clear(); 236 stream_header_.clear();
236 } 237 }
237 encoded_frame->data.append( 238 encoded_frame->data.append(
238 static_cast<const char*>(output_buffer->memory()), payload_size); 239 static_cast<const char*>(output_buffer->memory()), payload_size);
239 240
240 // If FRAME_DURATION metadata was provided in the source VideoFrame, 241 // If FRAME_DURATION metadata was provided in the source VideoFrame,
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 // which causes crypto crashes. http://crbug.com/519022 307 // which causes crypto crashes. http://crbug.com/519022
307 if (!has_seen_zero_length_encoded_frame_ && encoded_frame->data.empty()) { 308 if (!has_seen_zero_length_encoded_frame_ && encoded_frame->data.empty()) {
308 has_seen_zero_length_encoded_frame_ = true; 309 has_seen_zero_length_encoded_frame_ = true;
309 310
310 const char kZeroEncodeDetails[] = "zero-encode-details"; 311 const char kZeroEncodeDetails[] = "zero-encode-details";
311 const std::string details = base::StringPrintf( 312 const std::string details = base::StringPrintf(
312 ("%c/%c,id=%" PRIu32 ",rtp=%" PRIu32 ",br=%d,q=%" PRIuS 313 ("%c/%c,id=%" PRIu32 ",rtp=%" PRIu32 ",br=%d,q=%" PRIuS
313 ",act=%c,ref=%d"), 314 ",act=%c,ref=%d"),
314 codec_profile_ == media::VP8PROFILE_ANY ? 'V' : 'H', 315 codec_profile_ == media::VP8PROFILE_ANY ? 'V' : 'H',
315 key_frame ? 'K' : 'D', encoded_frame->frame_id, 316 key_frame ? 'K' : 'D', encoded_frame->frame_id,
316 encoded_frame->rtp_timestamp, request.target_bit_rate / 1000, 317 encoded_frame->rtp_timestamp.lower_32_bits(),
317 in_progress_frame_encodes_.size(), encoder_active_ ? 'Y' : 'N', 318 request.target_bit_rate / 1000, in_progress_frame_encodes_.size(),
319 encoder_active_ ? 'Y' : 'N',
318 static_cast<int>(encoded_frame->referenced_frame_id % 1000)); 320 static_cast<int>(encoded_frame->referenced_frame_id % 1000));
319 base::debug::SetCrashKeyValue(kZeroEncodeDetails, details); 321 base::debug::SetCrashKeyValue(kZeroEncodeDetails, details);
320 // Please forward crash reports to http://crbug.com/519022: 322 // Please forward crash reports to http://crbug.com/519022:
321 base::debug::DumpWithoutCrashing(); 323 base::debug::DumpWithoutCrashing();
322 base::debug::ClearCrashKey(kZeroEncodeDetails); 324 base::debug::ClearCrashKey(kZeroEncodeDetails);
323 } 325 }
324 326
325 encoded_frame->encode_completion_time = 327 encoded_frame->encode_completion_time =
326 cast_environment_->Clock()->NowTicks(); 328 cast_environment_->Clock()->NowTicks();
327 cast_environment_->PostTask( 329 cast_environment_->PostTask(
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 const double kEntropyAtMaxQuantizer = 7.5; 787 const double kEntropyAtMaxQuantizer = 7.5;
786 const double slope = 788 const double slope =
787 (MAX_VP8_QUANTIZER - MIN_VP8_QUANTIZER) / kEntropyAtMaxQuantizer; 789 (MAX_VP8_QUANTIZER - MIN_VP8_QUANTIZER) / kEntropyAtMaxQuantizer;
788 const double quantizer = std::min<double>( 790 const double quantizer = std::min<double>(
789 MAX_VP8_QUANTIZER, MIN_VP8_QUANTIZER + slope * shannon_entropy); 791 MAX_VP8_QUANTIZER, MIN_VP8_QUANTIZER + slope * shannon_entropy);
790 return quantizer; 792 return quantizer;
791 } 793 }
792 794
793 } // namespace cast 795 } // namespace cast
794 } // namespace media 796 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698