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

Side by Side Diff: media/cast/test/fake_media_source.cc

Issue 1544313002: Convert Pass()→std::move() in //media (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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
« no previous file with comments | « media/cast/test/end2end_unittest.cc ('k') | media/cast/test/loopback_transport.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/test/fake_media_source.h" 5 #include "media/cast/test/fake_media_source.h"
6 6
7 #include <utility>
8
7 #include "base/bind.h" 9 #include "base/bind.h"
8 #include "base/files/scoped_file.h" 10 #include "base/files/scoped_file.h"
9 #include "base/logging.h" 11 #include "base/logging.h"
10 #include "base/rand_util.h" 12 #include "base/rand_util.h"
11 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
12 #include "media/base/audio_buffer.h" 14 #include "media/base/audio_buffer.h"
13 #include "media/base/audio_bus.h" 15 #include "media/base/audio_bus.h"
14 #include "media/base/audio_fifo.h" 16 #include "media/base/audio_fifo.h"
15 #include "media/base/audio_timestamp_helper.h" 17 #include "media/base/audio_timestamp_helper.h"
16 #include "media/base/media.h" 18 #include "media/base/media.h"
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 start_time_ + video_time); 266 start_time_ + video_time);
265 267
266 // Send just enough audio data to match next video frame's time. 268 // Send just enough audio data to match next video frame's time.
267 base::TimeDelta audio_time = AudioFrameTime(audio_frame_count_); 269 base::TimeDelta audio_time = AudioFrameTime(audio_frame_count_);
268 while (audio_time < video_time) { 270 while (audio_time < video_time) {
269 if (is_transcoding_audio()) { 271 if (is_transcoding_audio()) {
270 Decode(true); 272 Decode(true);
271 CHECK(!audio_bus_queue_.empty()) << "No audio decoded."; 273 CHECK(!audio_bus_queue_.empty()) << "No audio decoded.";
272 scoped_ptr<AudioBus> bus(audio_bus_queue_.front()); 274 scoped_ptr<AudioBus> bus(audio_bus_queue_.front());
273 audio_bus_queue_.pop(); 275 audio_bus_queue_.pop();
274 audio_frame_input_->InsertAudio( 276 audio_frame_input_->InsertAudio(std::move(bus), start_time_ + audio_time);
275 bus.Pass(), start_time_ + audio_time);
276 } else { 277 } else {
277 audio_frame_input_->InsertAudio( 278 audio_frame_input_->InsertAudio(
278 audio_bus_factory_->NextAudioBus( 279 audio_bus_factory_->NextAudioBus(
279 base::TimeDelta::FromMilliseconds(kAudioFrameMs)), 280 base::TimeDelta::FromMilliseconds(kAudioFrameMs)),
280 start_time_ + audio_time); 281 start_time_ + audio_time);
281 } 282 }
282 audio_time = AudioFrameTime(++audio_frame_count_); 283 audio_time = AudioFrameTime(++audio_frame_count_);
283 } 284 }
284 285
285 // This is the time since FakeMediaSource was started. 286 // This is the time since FakeMediaSource was started.
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 Decode(true); 358 Decode(true);
358 if (audio_bus_queue_.empty()) 359 if (audio_bus_queue_.empty())
359 return false; 360 return false;
360 361
361 base::TimeDelta audio_time = audio_sent_ts_->GetTimestamp(); 362 base::TimeDelta audio_time = audio_sent_ts_->GetTimestamp();
362 if (elapsed_time < audio_time) 363 if (elapsed_time < audio_time)
363 return false; 364 return false;
364 scoped_ptr<AudioBus> bus(audio_bus_queue_.front()); 365 scoped_ptr<AudioBus> bus(audio_bus_queue_.front());
365 audio_bus_queue_.pop(); 366 audio_bus_queue_.pop();
366 audio_sent_ts_->AddFrames(bus->frames()); 367 audio_sent_ts_->AddFrames(bus->frames());
367 audio_frame_input_->InsertAudio( 368 audio_frame_input_->InsertAudio(std::move(bus), start_time_ + audio_time);
368 bus.Pass(), start_time_ + audio_time);
369 369
370 // Make sure queue is not empty. 370 // Make sure queue is not empty.
371 Decode(true); 371 Decode(true);
372 return true; 372 return true;
373 } 373 }
374 374
375 void FakeMediaSource::SendNextFrame() { 375 void FakeMediaSource::SendNextFrame() {
376 // Send as much as possible. Audio is sent according to 376 // Send as much as possible. Audio is sent according to
377 // system time. 377 // system time.
378 while (SendNextTranscodedAudio(clock_->NowTicks() - start_time_)) { 378 while (SendNextTranscodedAudio(clock_->NowTicks() - start_time_)) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 void FakeMediaSource::Rewind() { 412 void FakeMediaSource::Rewind() {
413 CHECK(av_seek_frame(av_format_context_, -1, 0, AVSEEK_FLAG_BACKWARD) >= 0) 413 CHECK(av_seek_frame(av_format_context_, -1, 0, AVSEEK_FLAG_BACKWARD) >= 0)
414 << "Failed to rewind to the beginning."; 414 << "Failed to rewind to the beginning.";
415 } 415 }
416 416
417 ScopedAVPacket FakeMediaSource::DemuxOnePacket(bool* audio) { 417 ScopedAVPacket FakeMediaSource::DemuxOnePacket(bool* audio) {
418 ScopedAVPacket packet(new AVPacket()); 418 ScopedAVPacket packet(new AVPacket());
419 if (av_read_frame(av_format_context_, packet.get()) < 0) { 419 if (av_read_frame(av_format_context_, packet.get()) < 0) {
420 VLOG(1) << "Failed to read one AVPacket."; 420 VLOG(1) << "Failed to read one AVPacket.";
421 packet.reset(); 421 packet.reset();
422 return packet.Pass(); 422 return packet;
423 } 423 }
424 424
425 int stream_index = static_cast<int>(packet->stream_index); 425 int stream_index = static_cast<int>(packet->stream_index);
426 if (stream_index == audio_stream_index_) { 426 if (stream_index == audio_stream_index_) {
427 *audio = true; 427 *audio = true;
428 } else if (stream_index == video_stream_index_) { 428 } else if (stream_index == video_stream_index_) {
429 *audio = false; 429 *audio = false;
430 } else { 430 } else {
431 // Ignore unknown packet. 431 // Ignore unknown packet.
432 LOG(INFO) << "Unknown packet."; 432 LOG(INFO) << "Unknown packet.";
433 packet.reset(); 433 packet.reset();
434 } 434 }
435 return packet.Pass(); 435 return packet;
436 } 436 }
437 437
438 void FakeMediaSource::DecodeAudio(ScopedAVPacket packet) { 438 void FakeMediaSource::DecodeAudio(ScopedAVPacket packet) {
439 // Audio. 439 // Audio.
440 AVFrame* avframe = av_frame_alloc(); 440 AVFrame* avframe = av_frame_alloc();
441 441
442 // Make a shallow copy of packet so we can slide packet.data as frames are 442 // Make a shallow copy of packet so we can slide packet.data as frames are
443 // decoded from the packet; otherwise av_packet_unref() will corrupt memory. 443 // decoded from the packet; otherwise av_packet_unref() will corrupt memory.
444 AVPacket packet_temp = *packet.get(); 444 AVPacket packet_temp = *packet.get();
445 445
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 return; 563 return;
564 564
565 bool audio_packet = false; 565 bool audio_packet = false;
566 ScopedAVPacket packet = DemuxOnePacket(&audio_packet); 566 ScopedAVPacket packet = DemuxOnePacket(&audio_packet);
567 if (!packet) { 567 if (!packet) {
568 VLOG(1) << "End of stream."; 568 VLOG(1) << "End of stream.";
569 return; 569 return;
570 } 570 }
571 571
572 if (audio_packet) 572 if (audio_packet)
573 DecodeAudio(packet.Pass()); 573 DecodeAudio(std::move(packet));
574 else 574 else
575 DecodeVideo(packet.Pass()); 575 DecodeVideo(std::move(packet));
576 } 576 }
577 } 577 }
578 578
579 double FakeMediaSource::ProvideInput(media::AudioBus* output_bus, 579 double FakeMediaSource::ProvideInput(media::AudioBus* output_bus,
580 base::TimeDelta buffer_delay) { 580 base::TimeDelta buffer_delay) {
581 if (audio_fifo_->frames() >= output_bus->frames()) { 581 if (audio_fifo_->frames() >= output_bus->frames()) {
582 audio_fifo_->Consume(output_bus, 0, output_bus->frames()); 582 audio_fifo_->Consume(output_bus, 0, output_bus->frames());
583 return 1.0; 583 return 1.0;
584 } else { 584 } else {
585 LOG(WARNING) << "Not enough audio data for resampling."; 585 LOG(WARNING) << "Not enough audio data for resampling.";
(...skipping 22 matching lines...) Expand all
608 AVCodecContext* FakeMediaSource::av_audio_context() { 608 AVCodecContext* FakeMediaSource::av_audio_context() {
609 return av_audio_stream()->codec; 609 return av_audio_stream()->codec;
610 } 610 }
611 611
612 AVCodecContext* FakeMediaSource::av_video_context() { 612 AVCodecContext* FakeMediaSource::av_video_context() {
613 return av_video_stream()->codec; 613 return av_video_stream()->codec;
614 } 614 }
615 615
616 } // namespace cast 616 } // namespace cast
617 } // namespace media 617 } // namespace media
OLDNEW
« no previous file with comments | « media/cast/test/end2end_unittest.cc ('k') | media/cast/test/loopback_transport.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698