| OLD | NEW |
| 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 // Simulate end to end streaming. | 5 // Simulate end to end streaming. |
| 6 // | 6 // |
| 7 // Input: | 7 // Input: |
| 8 // --source= | 8 // --source= |
| 9 // WebM used as the source of video and audio frames. | 9 // WebM used as the source of video and audio frames. |
| 10 // --output= | 10 // --output= |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 CastLoggingEvent last_frame_event_type_; | 211 CastLoggingEvent last_frame_event_type_; |
| 212 std::queue<scoped_refptr<media::VideoFrame> > video_frames_; | 212 std::queue<scoped_refptr<media::VideoFrame> > video_frames_; |
| 213 | 213 |
| 214 DISALLOW_COPY_AND_ASSIGN(EncodedVideoFrameTracker); | 214 DISALLOW_COPY_AND_ASSIGN(EncodedVideoFrameTracker); |
| 215 }; | 215 }; |
| 216 | 216 |
| 217 // Appends a YUV frame in I420 format to the file located at |path|. | 217 // Appends a YUV frame in I420 format to the file located at |path|. |
| 218 void AppendYuvToFile(const base::FilePath& path, | 218 void AppendYuvToFile(const base::FilePath& path, |
| 219 scoped_refptr<media::VideoFrame> frame) { | 219 scoped_refptr<media::VideoFrame> frame) { |
| 220 // Write YUV420 format to file. | 220 // Write YUV420 format to file. |
| 221 std::string header = "FRAME\n"; | 221 std::string header; |
| 222 base::StringAppendF( |
| 223 &header, "FRAME W%d H%d\n", |
| 224 frame->coded_size().width(), |
| 225 frame->coded_size().height()); |
| 222 AppendToFile(path, header.data(), header.size()); | 226 AppendToFile(path, header.data(), header.size()); |
| 223 AppendToFile(path, | 227 AppendToFile(path, |
| 224 reinterpret_cast<char*>(frame->data(media::VideoFrame::kYPlane)), | 228 reinterpret_cast<char*>(frame->data(media::VideoFrame::kYPlane)), |
| 225 frame->stride(media::VideoFrame::kYPlane) * | 229 frame->stride(media::VideoFrame::kYPlane) * |
| 226 frame->rows(media::VideoFrame::kYPlane)); | 230 frame->rows(media::VideoFrame::kYPlane)); |
| 227 AppendToFile(path, | 231 AppendToFile(path, |
| 228 reinterpret_cast<char*>(frame->data(media::VideoFrame::kUPlane)), | 232 reinterpret_cast<char*>(frame->data(media::VideoFrame::kUPlane)), |
| 229 frame->stride(media::VideoFrame::kUPlane) * | 233 frame->stride(media::VideoFrame::kUPlane) * |
| 230 frame->rows(media::VideoFrame::kUPlane)); | 234 frame->rows(media::VideoFrame::kUPlane)); |
| 231 AppendToFile(path, | 235 AppendToFile(path, |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 // Truncate YUV files to prepare for writing. | 511 // Truncate YUV files to prepare for writing. |
| 508 if (!yuv_output_path.empty()) { | 512 if (!yuv_output_path.empty()) { |
| 509 base::ScopedFILE file(base::OpenFile(yuv_output_path, "wb")); | 513 base::ScopedFILE file(base::OpenFile(yuv_output_path, "wb")); |
| 510 if (!file.get()) { | 514 if (!file.get()) { |
| 511 LOG(ERROR) << "Cannot save YUV output to file."; | 515 LOG(ERROR) << "Cannot save YUV output to file."; |
| 512 return; | 516 return; |
| 513 } | 517 } |
| 514 LOG(INFO) << "Writing YUV output to file: " << yuv_output_path.value(); | 518 LOG(INFO) << "Writing YUV output to file: " << yuv_output_path.value(); |
| 515 | 519 |
| 516 // Write YUV4MPEG2 header. | 520 // Write YUV4MPEG2 header. |
| 517 std::string header; | 521 const std::string header("YUV4MPEG2 W1280 H720 F30000:1001 Ip A1:1 C420\n"); |
| 518 base::StringAppendF( | |
| 519 &header, "YUV4MPEG2 W%d H%d F30000:1001 Ip A1:1 C420\n", | |
| 520 media_source.get_video_config().width, | |
| 521 media_source.get_video_config().height); | |
| 522 AppendToFile(yuv_output_path, header.data(), header.size()); | 522 AppendToFile(yuv_output_path, header.data(), header.size()); |
| 523 } | 523 } |
| 524 | 524 |
| 525 // Start sending. | 525 // Start sending. |
| 526 if (!source_path.empty()) { | 526 if (!source_path.empty()) { |
| 527 // 0 means using the FPS from the file. | 527 // 0 means using the FPS from the file. |
| 528 media_source.SetSourceFile(source_path, | 528 media_source.SetSourceFile(source_path, |
| 529 GetIntegerSwitchValue(kSourceFrameRate, 0)); | 529 GetIntegerSwitchValue(kSourceFrameRate, 0)); |
| 530 } | 530 } |
| 531 media_source.Start(cast_sender->audio_frame_input(), | 531 media_source.Start(cast_sender->audio_frame_input(), |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 765 values.SetString("sim-id", sim_id); | 765 values.SetString("sim-id", sim_id); |
| 766 | 766 |
| 767 std::string extra_data; | 767 std::string extra_data; |
| 768 base::JSONWriter::Write(&values, &extra_data); | 768 base::JSONWriter::Write(&values, &extra_data); |
| 769 | 769 |
| 770 // Run. | 770 // Run. |
| 771 media::cast::RunSimulation(source_path, log_output_path, metrics_output_path, | 771 media::cast::RunSimulation(source_path, log_output_path, metrics_output_path, |
| 772 yuv_output_path, extra_data, model); | 772 yuv_output_path, extra_data, model); |
| 773 return 0; | 773 return 0; |
| 774 } | 774 } |
| OLD | NEW |