OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <inttypes.h> | 5 #include <inttypes.h> |
6 #include <stddef.h> | 6 #include <stddef.h> |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
11 #include <queue> | 11 #include <queue> |
12 #include <string> | 12 #include <string> |
13 #include <utility> | 13 #include <utility> |
14 | 14 |
15 #include "base/at_exit.h" | 15 #include "base/at_exit.h" |
16 #include "base/bind.h" | 16 #include "base/bind.h" |
17 #include "base/command_line.h" | 17 #include "base/command_line.h" |
18 #include "base/files/file_util.h" | 18 #include "base/files/file_util.h" |
19 #include "base/files/memory_mapped_file.h" | 19 #include "base/files/memory_mapped_file.h" |
20 #include "base/macros.h" | 20 #include "base/macros.h" |
21 #include "base/memory/scoped_vector.h" | 21 #include "base/memory/scoped_vector.h" |
22 #include "base/message_loop/message_loop.h" | 22 #include "base/message_loop/message_loop.h" |
23 #include "base/numerics/safe_conversions.h" | 23 #include "base/numerics/safe_conversions.h" |
24 #include "base/process/process_handle.h" | 24 #include "base/process/process_handle.h" |
| 25 #include "base/single_thread_task_runner.h" |
25 #include "base/strings/string_number_conversions.h" | 26 #include "base/strings/string_number_conversions.h" |
26 #include "base/strings/string_split.h" | 27 #include "base/strings/string_split.h" |
27 #include "base/strings/stringprintf.h" | 28 #include "base/strings/stringprintf.h" |
28 #include "base/threading/thread.h" | 29 #include "base/threading/thread.h" |
29 #include "base/threading/thread_checker.h" | 30 #include "base/threading/thread_checker.h" |
30 #include "base/time/time.h" | 31 #include "base/time/time.h" |
31 #include "base/timer/timer.h" | 32 #include "base/timer/timer.h" |
32 #include "build/build_config.h" | 33 #include "build/build_config.h" |
33 #include "media/base/bind_to_current_loop.h" | 34 #include "media/base/bind_to_current_loop.h" |
34 #include "media/base/bitstream_buffer.h" | 35 #include "media/base/bitstream_buffer.h" |
(...skipping 1549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1584 bool encoder_save_to_file = | 1585 bool encoder_save_to_file = |
1585 (save_to_file && | 1586 (save_to_file && |
1586 !g_env->test_streams_[test_stream_index]->out_filename.empty()); | 1587 !g_env->test_streams_[test_stream_index]->out_filename.empty()); |
1587 | 1588 |
1588 notes.push_back(new ClientStateNotification<ClientState>()); | 1589 notes.push_back(new ClientStateNotification<ClientState>()); |
1589 clients.push_back(new VEAClient( | 1590 clients.push_back(new VEAClient( |
1590 g_env->test_streams_[test_stream_index], notes.back(), | 1591 g_env->test_streams_[test_stream_index], notes.back(), |
1591 encoder_save_to_file, keyframe_period, force_bitrate, test_perf, | 1592 encoder_save_to_file, keyframe_period, force_bitrate, test_perf, |
1592 mid_stream_bitrate_switch, mid_stream_framerate_switch, verify_output)); | 1593 mid_stream_bitrate_switch, mid_stream_framerate_switch, verify_output)); |
1593 | 1594 |
1594 encoder_thread.message_loop()->PostTask( | 1595 encoder_thread.task_runner()->PostTask( |
1595 FROM_HERE, base::Bind(&VEAClient::CreateEncoder, | 1596 FROM_HERE, base::Bind(&VEAClient::CreateEncoder, |
1596 base::Unretained(clients.back()))); | 1597 base::Unretained(clients.back()))); |
1597 } | 1598 } |
1598 | 1599 |
1599 // All encoders must pass through states in this order. | 1600 // All encoders must pass through states in this order. |
1600 enum ClientState state_transitions[] = { | 1601 enum ClientState state_transitions[] = { |
1601 CS_ENCODER_SET, CS_INITIALIZED, CS_ENCODING, CS_FINISHED, CS_VALIDATED}; | 1602 CS_ENCODER_SET, CS_INITIALIZED, CS_ENCODING, CS_FINISHED, CS_VALIDATED}; |
1602 | 1603 |
1603 // Wait for all encoders to go through all states and finish. | 1604 // Wait for all encoders to go through all states and finish. |
1604 // Do this by waiting for all encoders to advance to state n before checking | 1605 // Do this by waiting for all encoders to advance to state n before checking |
1605 // state n+1, to verify that they are able to operate concurrently. | 1606 // state n+1, to verify that they are able to operate concurrently. |
1606 // It also simulates the real-world usage better, as the main thread, on which | 1607 // It also simulates the real-world usage better, as the main thread, on which |
1607 // encoders are created/destroyed, is a single GPU Process ChildThread. | 1608 // encoders are created/destroyed, is a single GPU Process ChildThread. |
1608 // Moreover, we can't have proper multithreading on X11, so this could cause | 1609 // Moreover, we can't have proper multithreading on X11, so this could cause |
1609 // hard to debug issues there, if there were multiple "ChildThreads". | 1610 // hard to debug issues there, if there were multiple "ChildThreads". |
1610 for (size_t state_no = 0; state_no < arraysize(state_transitions); | 1611 for (size_t state_no = 0; state_no < arraysize(state_transitions); |
1611 ++state_no) { | 1612 ++state_no) { |
1612 for (size_t i = 0; i < num_concurrent_encoders; i++) | 1613 for (size_t i = 0; i < num_concurrent_encoders; i++) |
1613 ASSERT_EQ(notes[i]->Wait(), state_transitions[state_no]); | 1614 ASSERT_EQ(notes[i]->Wait(), state_transitions[state_no]); |
1614 } | 1615 } |
1615 | 1616 |
1616 for (size_t i = 0; i < num_concurrent_encoders; ++i) { | 1617 for (size_t i = 0; i < num_concurrent_encoders; ++i) { |
1617 encoder_thread.message_loop()->PostTask( | 1618 encoder_thread.task_runner()->PostTask( |
1618 FROM_HERE, | 1619 FROM_HERE, |
1619 base::Bind(&VEAClient::DestroyEncoder, base::Unretained(clients[i]))); | 1620 base::Bind(&VEAClient::DestroyEncoder, base::Unretained(clients[i]))); |
1620 } | 1621 } |
1621 | 1622 |
1622 // This ensures all tasks have finished. | 1623 // This ensures all tasks have finished. |
1623 encoder_thread.Stop(); | 1624 encoder_thread.Stop(); |
1624 } | 1625 } |
1625 | 1626 |
1626 #if !defined(OS_MACOSX) | 1627 #if !defined(OS_MACOSX) |
1627 INSTANTIATE_TEST_CASE_P( | 1628 INSTANTIATE_TEST_CASE_P( |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1777 | 1778 |
1778 media::g_env = | 1779 media::g_env = |
1779 reinterpret_cast<media::VideoEncodeAcceleratorTestEnvironment*>( | 1780 reinterpret_cast<media::VideoEncodeAcceleratorTestEnvironment*>( |
1780 testing::AddGlobalTestEnvironment( | 1781 testing::AddGlobalTestEnvironment( |
1781 new media::VideoEncodeAcceleratorTestEnvironment( | 1782 new media::VideoEncodeAcceleratorTestEnvironment( |
1782 std::move(test_stream_data), log_path, run_at_fps, | 1783 std::move(test_stream_data), log_path, run_at_fps, |
1783 needs_encode_latency, verify_all_output))); | 1784 needs_encode_latency, verify_all_output))); |
1784 | 1785 |
1785 return RUN_ALL_TESTS(); | 1786 return RUN_ALL_TESTS(); |
1786 } | 1787 } |
OLD | NEW |