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 void AppendLog(media::cast::proto::LogMetadata* metadata, |
hubbe
2014/08/04 22:37:24
Document with comment?
Alpha Left Google
2014/08/04 22:44:09
Done.
| |
149 const std::string& extra_data, | 149 const media::cast::FrameEventList& frame_events, |
150 const media::cast::PacketEventList& packet_events, | |
150 const base::FilePath& output_path) { | 151 const base::FilePath& output_path) { |
151 media::cast::proto::LogMetadata metadata; | |
152 metadata.set_extra_data(extra_data); | |
153 | |
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 = | 152 media::cast::proto::GeneralDescription* gen_desc = |
159 metadata.mutable_general_description(); | 153 metadata->mutable_general_description(); |
160 gen_desc->set_product("Cast Simulator"); | 154 gen_desc->set_product("Cast Simulator"); |
161 gen_desc->set_product_version("0.1"); | 155 gen_desc->set_product_version("0.1"); |
162 | 156 |
163 scoped_ptr<char[]> serialized_log(new char[media::cast::kMaxSerializedBytes]); | 157 scoped_ptr<char[]> serialized_log(new char[media::cast::kMaxSerializedBytes]); |
164 int output_bytes; | 158 int output_bytes; |
165 bool success = media::cast::SerializeEvents(metadata, | 159 bool success = media::cast::SerializeEvents(*metadata, |
166 frame_events, | 160 frame_events, |
167 packet_events, | 161 packet_events, |
168 true, | 162 true, |
169 media::cast::kMaxSerializedBytes, | 163 media::cast::kMaxSerializedBytes, |
170 serialized_log.get(), | 164 serialized_log.get(), |
171 &output_bytes); | 165 &output_bytes); |
172 | 166 |
173 if (!success) { | 167 if (!success) { |
174 LOG(ERROR) << "Failed to serialize log."; | 168 LOG(ERROR) << "Failed to serialize log."; |
175 return; | 169 return; |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
324 // Run for 3 minutes. | 318 // Run for 3 minutes. |
325 base::TimeDelta elapsed_time; | 319 base::TimeDelta elapsed_time; |
326 while (elapsed_time.InMinutes() < 3) { | 320 while (elapsed_time.InMinutes() < 3) { |
327 // Each step is 100us. | 321 // Each step is 100us. |
328 base::TimeDelta step = base::TimeDelta::FromMicroseconds(100); | 322 base::TimeDelta step = base::TimeDelta::FromMicroseconds(100); |
329 task_runner->Sleep(step); | 323 task_runner->Sleep(step); |
330 elapsed_time += step; | 324 elapsed_time += step; |
331 } | 325 } |
332 | 326 |
333 LOG(INFO) << "Audio frame count: " << audio_frame_count; | 327 LOG(INFO) << "Audio frame count: " << audio_frame_count; |
334 LOG(INFO) << "Video frame count: " << video_frame_count; | |
335 LOG(INFO) << "Writing log: " << output_path.value(); | |
336 | 328 |
337 // Truncate file and then write serialized log. | 329 // Truncate file and then write serialized log. |
338 { | 330 { |
339 base::ScopedFILE file(base::OpenFile(output_path, "wb")); | 331 base::ScopedFILE file(base::OpenFile(output_path, "wb")); |
340 if (!file.get()) { | 332 if (!file.get()) { |
341 LOG(INFO) << "Cannot write to log."; | 333 LOG(INFO) << "Cannot write to log."; |
342 return; | 334 return; |
343 } | 335 } |
344 } | 336 } |
345 AppendLog(&video_event_subscriber, extra_data, output_path); | 337 |
346 AppendLog(&audio_event_subscriber, extra_data, output_path); | 338 media::cast::proto::LogMetadata audio_metadata, video_metadata; |
hubbe
2014/08/04 22:37:24
This is a giant function, but each block above has
Alpha Left Google
2014/08/04 22:44:09
Done.
| |
339 audio_metadata.set_extra_data(extra_data); | |
340 video_metadata.set_extra_data(extra_data); | |
341 | |
342 media::cast::FrameEventList audio_frame_events, video_frame_events; | |
343 media::cast::PacketEventList audio_packet_events, video_packet_events; | |
344 audio_event_subscriber.GetEventsAndReset( | |
345 &audio_metadata, &audio_frame_events, &audio_packet_events); | |
346 video_event_subscriber.GetEventsAndReset( | |
347 &video_metadata, &video_frame_events, &video_packet_events); | |
348 | |
349 int total_video_frames = 0; | |
350 int encoded_video_frames = 0; | |
351 int dropped_video_frames = 0; | |
352 int late_video_frames = 0; | |
353 int64 encoded_size = 0; | |
354 int64 target_bitrate = 0; | |
355 for (size_t i = 0; i < video_frame_events.size(); ++i) { | |
356 const media::cast::proto::AggregatedFrameEvent& event = | |
357 *video_frame_events[i]; | |
358 ++total_video_frames; | |
359 if (event.has_encoded_frame_size()) { | |
360 ++encoded_video_frames; | |
361 encoded_size += event.encoded_frame_size(); | |
362 target_bitrate += event.target_bitrate(); | |
363 } else { | |
364 ++dropped_video_frames; | |
365 } | |
366 if (event.has_delay_millis() && event.delay_millis() < 0) | |
367 ++late_video_frames; | |
368 } | |
369 | |
370 double avg_encoded_bitrate = | |
371 !encoded_video_frames ? 0 : | |
372 8.0 * encoded_size * video_sender_config.max_frame_rate / | |
373 encoded_video_frames / 1000; | |
374 double avg_target_bitrate = | |
375 !encoded_video_frames ? 0 : target_bitrate / encoded_video_frames / 1000; | |
376 | |
377 LOG(INFO) << "Total video frames: " << total_video_frames; | |
378 LOG(INFO) << "Dropped video frames " << dropped_video_frames; | |
379 LOG(INFO) << "Late video frames: " << late_video_frames; | |
380 LOG(INFO) << "Average encoded bitrate (kbps): " << avg_encoded_bitrate; | |
381 LOG(INFO) << "Average target bitrate (kbps): " << avg_target_bitrate; | |
382 LOG(INFO) << "Writing log: " << output_path.value(); | |
383 AppendLog(&video_metadata, video_frame_events, video_packet_events, | |
384 output_path); | |
385 AppendLog(&audio_metadata, audio_frame_events, audio_packet_events, | |
386 output_path); | |
347 } | 387 } |
348 | 388 |
349 NetworkSimulationModel DefaultModel() { | 389 NetworkSimulationModel DefaultModel() { |
350 NetworkSimulationModel model; | 390 NetworkSimulationModel model; |
351 model.set_type(cast::proto::INTERRUPTED_POISSON_PROCESS); | 391 model.set_type(cast::proto::INTERRUPTED_POISSON_PROCESS); |
352 IPPModel* ipp = model.mutable_ipp(); | 392 IPPModel* ipp = model.mutable_ipp(); |
353 ipp->set_coef_burstiness(0.609); | 393 ipp->set_coef_burstiness(0.609); |
354 ipp->set_coef_variance(4.1); | 394 ipp->set_coef_variance(4.1); |
355 | 395 |
356 ipp->add_average_rate(0.609); | 396 ipp->add_average_rate(0.609); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
458 values.SetBoolean("sim", true); | 498 values.SetBoolean("sim", true); |
459 values.SetString("sim-id", sim_id); | 499 values.SetString("sim-id", sim_id); |
460 | 500 |
461 std::string extra_data; | 501 std::string extra_data; |
462 base::JSONWriter::Write(&values, &extra_data); | 502 base::JSONWriter::Write(&values, &extra_data); |
463 | 503 |
464 // Run. | 504 // Run. |
465 media::cast::RunSimulation(source_path, output_path, extra_data, model); | 505 media::cast::RunSimulation(source_path, output_path, extra_data, model); |
466 return 0; | 506 return 0; |
467 } | 507 } |
OLD | NEW |