Improve android MediaDrm property latency
[ Merge of http://go/wvgerrit/89848 ] Apps query a number of properties at initialization. The mediaDrm API getProperty allows the query of a single property at a time. This causes a series of requests. If no crypto sessions are concurrently open, a series of expensive OEMCrypto Initialization and Termination calls will occur. In this change OEMCrypto termination is delayed. If an OEMCrypto Terminate is followed in close succession by an Initialize, neither will occur avoiding the overhead. A timer enables a countdown process. If no session activity occurs, the timer will eventually terminate OEMCrypto and exit. Bug: 136282358 Test: Android unit/integration tests Change-Id: I442b7919b4e7835c52583516c8bc64d0c150241d
This commit is contained in:
@@ -8,17 +8,46 @@
|
||||
|
||||
namespace wvcdm {
|
||||
|
||||
namespace {
|
||||
|
||||
// duration in seconds after starting the timer
|
||||
constexpr uint32_t kTestDuration = 5;
|
||||
// duration in seconds after test completes, before evaluating the result
|
||||
constexpr uint32_t kPostTestDuration = 3;
|
||||
|
||||
} // namespace
|
||||
|
||||
class TestTimerHandler : public TimerHandler {
|
||||
public:
|
||||
TestTimerHandler() : timer_events_(0){};
|
||||
TestTimerHandler() : timer_events_count_(0){};
|
||||
virtual ~TestTimerHandler(){};
|
||||
|
||||
virtual void OnTimerEvent() { timer_events_++; }
|
||||
virtual void OnTimerEvent() { timer_events_count_++; }
|
||||
|
||||
uint32_t timer_events() { return timer_events_; }
|
||||
uint32_t timer_events_count() { return timer_events_count_; }
|
||||
|
||||
private:
|
||||
uint32_t timer_events_;
|
||||
protected:
|
||||
uint32_t timer_events_count_;
|
||||
};
|
||||
|
||||
class TestStopTimerHandler : public TestTimerHandler {
|
||||
public:
|
||||
TestStopTimerHandler(uint32_t stop_at_timer_events_count, Timer* timer)
|
||||
: stop_at_timer_events_count_(stop_at_timer_events_count),
|
||||
timer_(timer) {}
|
||||
virtual ~TestStopTimerHandler() {}
|
||||
|
||||
virtual void OnTimerEvent() {
|
||||
if (++timer_events_count_ >= stop_at_timer_events_count_) {
|
||||
if (timer_ != nullptr) {
|
||||
timer_->Stop(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
uint32_t stop_at_timer_events_count_;
|
||||
Timer* timer_;
|
||||
};
|
||||
|
||||
TEST(TimerTest, ParametersCheck) {
|
||||
@@ -29,25 +58,58 @@ TEST(TimerTest, ParametersCheck) {
|
||||
EXPECT_FALSE(timer.Start(&handler, 0));
|
||||
}
|
||||
|
||||
TEST(TimerTest, TimerCheck) {
|
||||
TEST(TimerTest, TimerCheck_StopAndWaitForExit) {
|
||||
TestTimerHandler handler;
|
||||
Timer timer;
|
||||
uint32_t duration = 10;
|
||||
|
||||
EXPECT_EQ(0u, handler.timer_events());
|
||||
EXPECT_EQ(0u, handler.timer_events_count());
|
||||
EXPECT_FALSE(timer.IsRunning());
|
||||
|
||||
EXPECT_TRUE(timer.Start(&handler, 1));
|
||||
EXPECT_TRUE(timer.IsRunning());
|
||||
sleep(duration);
|
||||
sleep(kTestDuration);
|
||||
|
||||
EXPECT_LE(duration - 1, handler.timer_events());
|
||||
EXPECT_LE(handler.timer_events(), duration + 1);
|
||||
timer.Stop();
|
||||
EXPECT_LE(kTestDuration - 1, handler.timer_events_count());
|
||||
EXPECT_LE(handler.timer_events_count(), kTestDuration + 1);
|
||||
timer.Stop(true);
|
||||
EXPECT_FALSE(timer.IsRunning());
|
||||
sleep(duration);
|
||||
sleep(kPostTestDuration);
|
||||
|
||||
EXPECT_LE(duration - 1, handler.timer_events());
|
||||
EXPECT_LE(handler.timer_events(), duration + 1);
|
||||
EXPECT_LE(kTestDuration - 1, handler.timer_events_count());
|
||||
EXPECT_LE(handler.timer_events_count(), kTestDuration + 1);
|
||||
}
|
||||
|
||||
TEST(TimerTest, TimerCheck_Stop) {
|
||||
TestTimerHandler handler;
|
||||
Timer timer;
|
||||
|
||||
EXPECT_EQ(0u, handler.timer_events_count());
|
||||
EXPECT_FALSE(timer.IsRunning());
|
||||
|
||||
EXPECT_TRUE(timer.Start(&handler, 1));
|
||||
EXPECT_TRUE(timer.IsRunning());
|
||||
sleep(kTestDuration);
|
||||
|
||||
EXPECT_LE(kTestDuration - 1, handler.timer_events_count());
|
||||
EXPECT_LE(handler.timer_events_count(), kTestDuration + 1);
|
||||
timer.Stop(false);
|
||||
sleep(kPostTestDuration);
|
||||
|
||||
EXPECT_FALSE(timer.IsRunning());
|
||||
}
|
||||
|
||||
TEST(TimerTest, StopOnTimerThread) {
|
||||
Timer timer;
|
||||
TestStopTimerHandler handler(kTestDuration - 2, &timer);
|
||||
|
||||
EXPECT_EQ(0u, handler.timer_events_count());
|
||||
EXPECT_FALSE(timer.IsRunning());
|
||||
|
||||
EXPECT_TRUE(timer.Start(&handler, 1));
|
||||
EXPECT_TRUE(timer.IsRunning());
|
||||
sleep(kTestDuration + kPostTestDuration);
|
||||
|
||||
EXPECT_FALSE(timer.IsRunning());
|
||||
}
|
||||
|
||||
} // namespace wvcdm
|
||||
|
||||
Reference in New Issue
Block a user