Eliminate delay in MediaDrm.closeSession for widevine CDM
automerge: 16abc11
* commit '16abc110bbb1e44ecbf605ea5eb96cbb1229c5e7':
Eliminate delay in MediaDrm.closeSession for widevine CDM
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
#include "utils/RefBase.h"
|
#include "utils/RefBase.h"
|
||||||
#include "utils/StrongPointer.h"
|
#include "utils/StrongPointer.h"
|
||||||
#include "utils/Thread.h"
|
#include "utils/Thread.h"
|
||||||
|
#include "utils/Mutex.h"
|
||||||
|
|
||||||
namespace wvcdm {
|
namespace wvcdm {
|
||||||
|
|
||||||
@@ -15,27 +16,35 @@ class Timer::Impl : virtual public android::RefBase {
|
|||||||
private:
|
private:
|
||||||
class ImplThread : public android::Thread {
|
class ImplThread : public android::Thread {
|
||||||
public:
|
public:
|
||||||
ImplThread() : Thread(false), handler_(NULL), period_(0) {}
|
ImplThread() : Thread(false), handler_(NULL), period_ns_(0) {}
|
||||||
virtual ~ImplThread() {};
|
virtual ~ImplThread() {};
|
||||||
|
|
||||||
bool Start(TimerHandler *handler, uint32_t time_in_secs) {
|
bool Start(TimerHandler *handler, uint32_t time_in_secs) {
|
||||||
handler_ = handler;
|
handler_ = handler;
|
||||||
period_ = time_in_secs;
|
period_ns_ = time_in_secs * 1000000000ll;
|
||||||
return run() == android::NO_ERROR;
|
return run() == android::NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Stop() {
|
||||||
|
{
|
||||||
|
android::Mutex::Autolock autoLock(lock_);
|
||||||
|
stop_condition_.signal();
|
||||||
|
}
|
||||||
|
requestExitAndWait();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual bool threadLoop() {
|
virtual bool threadLoop() {
|
||||||
struct timeval timeout;
|
android::Mutex::Autolock autoLock(lock_);
|
||||||
timeout.tv_sec = period_;
|
stop_condition_.waitRelative(lock_, period_ns_);
|
||||||
timeout.tv_usec = 0;
|
|
||||||
TEMP_FAILURE_RETRY(select(0, NULL, NULL, NULL, &timeout));
|
|
||||||
handler_->OnTimerEvent();
|
handler_->OnTimerEvent();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TimerHandler *handler_;
|
TimerHandler *handler_;
|
||||||
uint32_t period_;
|
uint64_t period_ns_;
|
||||||
|
android::Mutex lock_;
|
||||||
|
android::Condition stop_condition_;
|
||||||
|
|
||||||
CORE_DISALLOW_COPY_AND_ASSIGN(ImplThread);
|
CORE_DISALLOW_COPY_AND_ASSIGN(ImplThread);
|
||||||
};
|
};
|
||||||
@@ -52,7 +61,7 @@ class Timer::Impl : virtual public android::RefBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Stop() {
|
void Stop() {
|
||||||
impl_thread_->requestExitAndWait();
|
impl_thread_->Stop();
|
||||||
impl_thread_.clear();
|
impl_thread_.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user