DO NOT MERGE mm-video-v4l2: vdec: Avoid processing ETBs/FTBs in invalid states

(per the spec) ETB/FTB should not be handled in states other than
Executing, Paused and Idle. This avoids accessing invalid buffers.
Also add a lock to protect the private-buffers from being deleted
while accessing from another thread.

Bug: 27890802
Security Vulnerability - Heap Use-After-Free and Possible LPE in
MediaServer (libOmxVdec problem #6)

CRs-Fixed: 1008882

Change-Id: Iaac2e383cd53cf9cf8042c9ed93ddc76dba3907e

void omx_vdec::adjust_timestamp(OMX_S64 &act_timestamp)
{
 if (rst_prev_ts && VALID_TS(act_timestamp)) {
        prev_ts = act_timestamp;
        rst_prev_ts = false;
 } else if (VALID_TS(prev_ts)) {
 bool codec_cond = (drv_ctx.timestamp_adjust)?
 (!VALID_TS(act_timestamp) || act_timestamp < prev_ts || llabs(act_timestamp - prev_ts) <= 2000) :
 (!VALID_TS(act_timestamp) || act_timestamp <= prev_ts);
 if (frm_int > 0 && codec_cond) {
            DEBUG_PRINT_LOW("adjust_timestamp: original ts[%lld]", act_timestamp);
            act_timestamp = prev_ts + frm_int;
            DEBUG_PRINT_LOW("adjust_timestamp: predicted ts[%lld]", act_timestamp);
            prev_ts = act_timestamp;
 } else {
 if (drv_ctx.picture_order == VDEC_ORDER_DISPLAY && act_timestamp < prev_ts) {
                act_timestamp = prev_ts;
 }
            set_frame_rate(act_timestamp);
 }
 } else if (frm_int > 0) // In this case the frame rate was set along
 { // with the port definition, start ts with 0
        act_timestamp = prev_ts = 0; // and correct if a valid ts is received.
        rst_prev_ts = true;
 }
}

void omx_vdec::adjust_timestamp(OMX_S64 &act_timestamp)
{
 if (rst_prev_ts && VALID_TS(act_timestamp)) {
        prev_ts = act_timestamp;
        rst_prev_ts = false;
 } else if (VALID_TS(prev_ts)) {
 bool codec_cond = (drv_ctx.timestamp_adjust)?
 (!VALID_TS(act_timestamp) || act_timestamp < prev_ts || llabs(act_timestamp - prev_ts) <= 2000) :
 (!VALID_TS(act_timestamp) || act_timestamp <= prev_ts);
 if (frm_int > 0 && codec_cond) {
            DEBUG_PRINT_LOW("adjust_timestamp: original ts[%lld]", act_timestamp);
            act_timestamp = prev_ts + frm_int;
            DEBUG_PRINT_LOW("adjust_timestamp: predicted ts[%lld]", act_timestamp);
            prev_ts = act_timestamp;
 } else {
 if (drv_ctx.picture_order == VDEC_ORDER_DISPLAY && act_timestamp < prev_ts) {
                act_timestamp = prev_ts;
 }
            set_frame_rate(act_timestamp);
 }
 } else if (frm_int > 0) // In this case the frame rate was set along
 { // with the port definition, start ts with 0
        act_timestamp = prev_ts = 0; // and correct if a valid ts is received.
        rst_prev_ts = true;
 }
}
