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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 int* counter, | 138 int* counter, |
139 CastReceiver* cast_receiver, | 139 CastReceiver* cast_receiver, |
140 scoped_ptr<AudioBus> audio_bus, | 140 scoped_ptr<AudioBus> audio_bus, |
141 const base::TimeTicks& playout_time, | 141 const base::TimeTicks& playout_time, |
142 bool is_continuous) { | 142 bool is_continuous) { |
143 ++*counter; | 143 ++*counter; |
144 cast_receiver->RequestDecodedAudioFrame( | 144 cast_receiver->RequestDecodedAudioFrame( |
145 base::Bind(&GotAudioFrame, counter, cast_receiver)); | 145 base::Bind(&GotAudioFrame, counter, cast_receiver)); |
146 } | 146 } |
147 | 147 |
148 void AppendLog(EncodingEventSubscriber* subscriber, | 148 // Serialize |frame_events| and |packet_events| and append to the file |
149 const std::string& extra_data, | 149 // located at |output_path|. |
150 const base::FilePath& output_path) { | 150 void AppendLogToFile(media::cast::proto::LogMetadata* metadata, |
151 media::cast::proto::LogMetadata metadata; | 151 const media::cast::FrameEventList& frame_events, |
152 metadata.set_extra_data(extra_data); | 152 const media::cast::PacketEventList& packet_events, |
153 | 153 const base::FilePath& output_path) { |
154 media::cast::FrameEventList frame_events; | |
155 media::cast::PacketEventList packet_events; | |
156 subscriber->GetEventsAndReset( | |
157 &metadata, &frame_events, &packet_events); | |
158 media::cast::proto::GeneralDescription* gen_desc = | 154 media::cast::proto::GeneralDescription* gen_desc = |
159 metadata.mutable_general_description(); | 155 metadata->mutable_general_description(); |
160 gen_desc->set_product("Cast Simulator"); | 156 gen_desc->set_product("Cast Simulator"); |
161 gen_desc->set_product_version("0.1"); | 157 gen_desc->set_product_version("0.1"); |
162 | 158 |
163 scoped_ptr<char[]> serialized_log(new char[media::cast::kMaxSerializedBytes]); | 159 scoped_ptr<char[]> serialized_log(new char[media::cast::kMaxSerializedBytes]); |
164 int output_bytes; | 160 int output_bytes; |
165 bool success = media::cast::SerializeEvents(metadata, | 161 bool success = media::cast::SerializeEvents(*metadata, |
166 frame_events, | 162 frame_events, |
167 packet_events, | 163 packet_events, |
168 true, | 164 true, |
169 media::cast::kMaxSerializedBytes, | 165 media::cast::kMaxSerializedBytes, |
170 serialized_log.get(), | 166 serialized_log.get(), |
171 &output_bytes); | 167 &output_bytes); |
172 | 168 |
173 if (!success) { | 169 if (!success) { |
174 LOG(ERROR) << "Failed to serialize log."; | 170 LOG(ERROR) << "Failed to serialize log."; |
175 return; | 171 return; |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 | 319 |
324 // Run for 3 minutes. | 320 // Run for 3 minutes. |
325 base::TimeDelta elapsed_time; | 321 base::TimeDelta elapsed_time; |
326 while (elapsed_time.InMinutes() < 3) { | 322 while (elapsed_time.InMinutes() < 3) { |
327 // Each step is 100us. | 323 // Each step is 100us. |
328 base::TimeDelta step = base::TimeDelta::FromMicroseconds(100); | 324 base::TimeDelta step = base::TimeDelta::FromMicroseconds(100); |
329 task_runner->Sleep(step); | 325 task_runner->Sleep(step); |
330 elapsed_time += step; | 326 elapsed_time += step; |
331 } | 327 } |
332 | 328 |
| 329 // Get event logs for audio and video. |
| 330 media::cast::proto::LogMetadata audio_metadata, video_metadata; |
| 331 media::cast::FrameEventList audio_frame_events, video_frame_events; |
| 332 media::cast::PacketEventList audio_packet_events, video_packet_events; |
| 333 audio_metadata.set_extra_data(extra_data); |
| 334 video_metadata.set_extra_data(extra_data); |
| 335 audio_event_subscriber.GetEventsAndReset( |
| 336 &audio_metadata, &audio_frame_events, &audio_packet_events); |
| 337 video_event_subscriber.GetEventsAndReset( |
| 338 &video_metadata, &video_frame_events, &video_packet_events); |
| 339 |
| 340 // Print simulation results. |
| 341 |
| 342 // Compute and print statistics for video: |
| 343 // |
| 344 // * Total video frames captured. |
| 345 // * Total video frames encoded. |
| 346 // * Total video frames dropped. |
| 347 // * Total video frames received late. |
| 348 // * Average target bitrate. |
| 349 // * Average encoded bitrate. |
| 350 int total_video_frames = 0; |
| 351 int encoded_video_frames = 0; |
| 352 int dropped_video_frames = 0; |
| 353 int late_video_frames = 0; |
| 354 int64 encoded_size = 0; |
| 355 int64 target_bitrate = 0; |
| 356 for (size_t i = 0; i < video_frame_events.size(); ++i) { |
| 357 const media::cast::proto::AggregatedFrameEvent& event = |
| 358 *video_frame_events[i]; |
| 359 ++total_video_frames; |
| 360 if (event.has_encoded_frame_size()) { |
| 361 ++encoded_video_frames; |
| 362 encoded_size += event.encoded_frame_size(); |
| 363 target_bitrate += event.target_bitrate(); |
| 364 } else { |
| 365 ++dropped_video_frames; |
| 366 } |
| 367 if (event.has_delay_millis() && event.delay_millis() < 0) |
| 368 ++late_video_frames; |
| 369 } |
| 370 |
| 371 double avg_encoded_bitrate = |
| 372 !encoded_video_frames ? 0 : |
| 373 8.0 * encoded_size * video_sender_config.max_frame_rate / |
| 374 encoded_video_frames / 1000; |
| 375 double avg_target_bitrate = |
| 376 !encoded_video_frames ? 0 : target_bitrate / encoded_video_frames / 1000; |
| 377 |
333 LOG(INFO) << "Audio frame count: " << audio_frame_count; | 378 LOG(INFO) << "Audio frame count: " << audio_frame_count; |
334 LOG(INFO) << "Video frame count: " << video_frame_count; | 379 LOG(INFO) << "Total video frames: " << total_video_frames; |
| 380 LOG(INFO) << "Dropped video frames " << dropped_video_frames; |
| 381 LOG(INFO) << "Late video frames: " << late_video_frames; |
| 382 LOG(INFO) << "Average encoded bitrate (kbps): " << avg_encoded_bitrate; |
| 383 LOG(INFO) << "Average target bitrate (kbps): " << avg_target_bitrate; |
335 LOG(INFO) << "Writing log: " << output_path.value(); | 384 LOG(INFO) << "Writing log: " << output_path.value(); |
336 | 385 |
337 // Truncate file and then write serialized log. | 386 // Truncate file and then write serialized log. |
338 { | 387 { |
339 base::ScopedFILE file(base::OpenFile(output_path, "wb")); | 388 base::ScopedFILE file(base::OpenFile(output_path, "wb")); |
340 if (!file.get()) { | 389 if (!file.get()) { |
341 LOG(INFO) << "Cannot write to log."; | 390 LOG(INFO) << "Cannot write to log."; |
342 return; | 391 return; |
343 } | 392 } |
344 } | 393 } |
345 AppendLog(&video_event_subscriber, extra_data, output_path); | 394 AppendLogToFile(&video_metadata, video_frame_events, video_packet_events, |
346 AppendLog(&audio_event_subscriber, extra_data, output_path); | 395 output_path); |
| 396 AppendLogToFile(&audio_metadata, audio_frame_events, audio_packet_events, |
| 397 output_path); |
347 } | 398 } |
348 | 399 |
349 NetworkSimulationModel DefaultModel() { | 400 NetworkSimulationModel DefaultModel() { |
350 NetworkSimulationModel model; | 401 NetworkSimulationModel model; |
351 model.set_type(cast::proto::INTERRUPTED_POISSON_PROCESS); | 402 model.set_type(cast::proto::INTERRUPTED_POISSON_PROCESS); |
352 IPPModel* ipp = model.mutable_ipp(); | 403 IPPModel* ipp = model.mutable_ipp(); |
353 ipp->set_coef_burstiness(0.609); | 404 ipp->set_coef_burstiness(0.609); |
354 ipp->set_coef_variance(4.1); | 405 ipp->set_coef_variance(4.1); |
355 | 406 |
356 ipp->add_average_rate(0.609); | 407 ipp->add_average_rate(0.609); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 values.SetBoolean("sim", true); | 509 values.SetBoolean("sim", true); |
459 values.SetString("sim-id", sim_id); | 510 values.SetString("sim-id", sim_id); |
460 | 511 |
461 std::string extra_data; | 512 std::string extra_data; |
462 base::JSONWriter::Write(&values, &extra_data); | 513 base::JSONWriter::Write(&values, &extra_data); |
463 | 514 |
464 // Run. | 515 // Run. |
465 media::cast::RunSimulation(source_path, output_path, extra_data, model); | 516 media::cast::RunSimulation(source_path, output_path, extra_data, model); |
466 return 0; | 517 return 0; |
467 } | 518 } |
OLD | NEW |