Value ffi_pointer_read(VMState *state, Object *type, void *ptr) { ValueCache *vcache = &state->shared->vcache; Object *string_base = vcache->string_base; FFIObject *ffi = (FFIObject*) vcache->ffi_obj; if (type == ffi->float_obj) { float f = *(float*) ptr; return FLOAT2VAL(f); } else if (type == ffi->int_obj) { int i = *(int*) ptr; return INT2VAL(i); } else if (type == ffi->uint_obj) { unsigned int i = *(unsigned int*) ptr; return INT2VAL(i); } else { bool has_pointer = false; OBJECT_LOOKUP_P(type, pointer, &has_pointer); if (!has_pointer) { Object *c_type_obj = OBJ_OR_NULL(OBJECT_LOOKUP(type, c_type)); StringObject *c_type = (StringObject*) obj_instance_of(c_type_obj, string_base); VM_ASSERT(c_type, "internal type error") VNULL; VM_ASSERT(false, "unhandled pointer read type: %s", c_type->value) VNULL; } Value res = make_object(state, type, false); char *error = OBJECT_SET(state, AS_OBJ(res), pointer, make_ffi_pointer(state, ptr)); VM_ASSERT(!error, error) VNULL; return res; } }
static void ffi_ptr_dereference_assign(VMState *state, CallInfo *info) { VM_ASSERT(info->args_len == 3, "wrong arity: expected 2, got %i", info->args_len); Object *root = state->root; Object *pointer_base = state->shared->vcache.pointer_base; FFIObject *ffi = (FFIObject*) AS_OBJ(OBJECT_LOOKUP(root, ffi)); Object *ffi_type = AS_OBJ(OBJECT_LOOKUP((Object*) ffi, type)); Object *thisptr = AS_OBJ(load_arg(state->frame, info->this_arg)); VM_ASSERT(thisptr->parent == pointer_base, "internal error"); PointerObject *thisptr_obj = (PointerObject*) thisptr; Object *ffi_type_obj = obj_instance_of(OBJ_OR_NULL(load_arg(state->frame, INFO_ARGS_PTR(info)[0])), ffi_type); Value offs_val = load_arg(state->frame, INFO_ARGS_PTR(info)[1]); VM_ASSERT(IS_INT(offs_val), "offset must be integer"); int offs = AS_INT(offs_val); VM_ASSERT(ffi_type_obj, "type is not a FFI type"); char *offset_ptr = (char*) thisptr_obj->ptr + offs; Value value = load_arg(state->frame, INFO_ARGS_PTR(info)[2]); (void) offset_ptr; (void) value; if (ffi_type_obj == ffi->long_obj) { VM_ASSERT(IS_INT(value), "can only assign integer to long"); *(long*) offset_ptr = AS_INT(value); } else { fprintf(stderr, "TODO\n"); abort(); } }
static void ffi_ptr_dereference(VMState *state, CallInfo *info) { VM_ASSERT(info->args_len == 2, "wrong arity: expected 2, got %i", info->args_len); Object *root = state->root; Object *pointer_base = state->shared->vcache.pointer_base; FFIObject *ffi = (FFIObject*) AS_OBJ(OBJECT_LOOKUP(root, ffi)); Object *ffi_type = AS_OBJ(OBJECT_LOOKUP((Object*) ffi, type)); Object *thisptr = AS_OBJ(load_arg(state->frame, info->this_arg)); VM_ASSERT(thisptr->parent == pointer_base, "internal error"); PointerObject *thisptr_obj = (PointerObject*) thisptr; Object *ffi_type_obj = obj_instance_of(OBJ_OR_NULL(load_arg(state->frame, INFO_ARGS_PTR(info)[0])), ffi_type); Value offs_val = load_arg(state->frame, INFO_ARGS_PTR(info)[1]); VM_ASSERT(IS_INT(offs_val), "offset must be integer"); int offs = AS_INT(offs_val); VM_ASSERT(ffi_type_obj, "type is not a FFI type"); char *offset_ptr = (char*) thisptr_obj->ptr + offs; if (ffi_type_obj == ffi->short_obj) { short s = *(short*) offset_ptr; vm_return(state, info, INT2VAL(s)); } else if (ffi_type_obj == ffi->ushort_obj) { unsigned short us = *(unsigned short*) offset_ptr; vm_return(state, info, INT2VAL(us)); } else if (ffi_type_obj == ffi->int_obj) { int i = *(int*) offset_ptr; vm_return(state, info, INT2VAL(i)); } else if (ffi_type_obj == ffi->uint_obj) { unsigned int u = *(unsigned int*) offset_ptr; vm_return(state, info, INT2VAL(u)); } else if (ffi_type_obj == ffi->int8_obj) { int8_t i8 = *(int8_t*) offset_ptr; vm_return(state, info, INT2VAL(i8)); } else if (ffi_type_obj == ffi->uint8_obj) { uint8_t u8 = *(uint8_t*) offset_ptr; vm_return(state, info, INT2VAL(u8)); } else if (ffi_type_obj == ffi->int32_obj) { int32_t i32 = *(int32_t*) offset_ptr; vm_return(state, info, INT2VAL(i32)); } else if (ffi_type_obj == ffi->uint32_obj) { uint32_t u32 = *(uint32_t*) offset_ptr; vm_return(state, info, INT2VAL(u32)); } else if (ffi_type_obj == ffi->pointer_obj) { void *ptr = *(void**) offset_ptr; vm_return(state, info, make_ffi_pointer(state, ptr)); } else if (ffi_type_obj == ffi->char_pointer_obj) { char *ptr = *(char**) offset_ptr; vm_return(state, info, make_string_static(state, ptr)); } else if (ffi_type_obj == ffi->long_obj) { long l = *(long*) offset_ptr; if (l < INT_MIN || l > INT_MAX) { VM_ASSERT(false, "value exceeds bounds of my int type"); } vm_return(state, info, INT2VAL((int) l)); } else { fprintf(stderr, "TODO\n"); abort(); } }
static void ffi_open_fn(VMState *state, CallInfo *info) { VM_ASSERT(info->args_len == 1, "wrong arity: expected 1, got %i", info->args_len); Object *root = state->root; Object *string_base = state->shared->vcache.string_base; Object *array_base = state->shared->vcache.array_base; Object *ffi = AS_OBJ(OBJECT_LOOKUP(root, ffi)); Object *handle_base = AS_OBJ(OBJECT_LOOKUP(ffi, handle)); StringObject *sarg = (StringObject*) obj_instance_of(OBJ_OR_NULL(load_arg(state->frame, INFO_ARGS_PTR(info)[0])), string_base); VM_ASSERT(sarg, "argument to ffi.open must be string!"); Object *libmap = AS_OBJ(OBJECT_LOOKUP(ffi, library_map)); char *file = sarg->value; bool file_found = false; FastKey file_key = prepare_key(file, strlen(file)); Value mapping = object_lookup_p(libmap, &file_key, &file_found); const char **file_list_ptr = NULL; int file_list_len = 0; if (file_found) { ArrayObject *aobj = (ArrayObject*) obj_instance_of(OBJ_OR_NULL(mapping), array_base); StringObject *sobj = (StringObject*) obj_instance_of(OBJ_OR_NULL(mapping), string_base); if (aobj) { file_list_len = aobj->length; file_list_ptr = malloc(sizeof(char*) * file_list_len); for (int i = 0; i < file_list_len; i++) { StringObject *file = (StringObject*) obj_instance_of(OBJ_OR_NULL(aobj->ptr[i]), string_base); VM_ASSERT(file, "library_map sub-entries must be string"); file_list_ptr[i] = my_asprintf("%s", file->value); // outside gc, make copy } } else if (sobj) { file_list_len = 1; file_list_ptr = malloc(sizeof(char*) * 1); file_list_ptr[0] = my_asprintf("%s", sobj->value); } else VM_ASSERT(false, "library_map entries must be string or array"); } else { file_list_len = 1; file_list_ptr = malloc(sizeof(char*) * 1); file_list_ptr[0] = file; } void *dlptr = my_dlopen(file_list_len, file_list_ptr); Object *handle_obj = AS_OBJ(make_object(state, handle_base, false)); handle_obj->flags |= OBJ_FROZEN; OBJECT_SET(state, handle_obj, pointer, make_ptr(state, dlptr)); vm_return(state, info, OBJ2VAL(handle_obj)); }
static ffi_type *type_to_ffi_ptr(VMState *state, Object *ffi_obj, Object *obj) { FFIObject *ffi = (FFIObject*) ffi_obj; if (obj == ffi->void_obj) return &ffi_type_void; if (obj == ffi->short_obj) return &ffi_type_sshort; if (obj == ffi->ushort_obj) return &ffi_type_ushort; if (obj == ffi->int_obj) return &ffi_type_sint; if (obj == ffi->uint_obj) return &ffi_type_uint; if (obj == ffi->long_obj) return &ffi_type_slong; if (obj == ffi->ulong_obj) return &ffi_type_ulong; if (obj == ffi->float_obj) return &ffi_type_float; if (obj == ffi->double_obj) return &ffi_type_double; if (obj == ffi->int8_obj) return &ffi_type_sint8; if (obj == ffi->int16_obj) return &ffi_type_sint16; if (obj == ffi->int32_obj) return &ffi_type_sint32; if (obj == ffi->int64_obj) return &ffi_type_sint64; if (obj == ffi->uint8_obj) return &ffi_type_uint8; if (obj == ffi->uint16_obj) return &ffi_type_uint16; if (obj == ffi->uint32_obj) return &ffi_type_uint32; if (obj == ffi->uint64_obj) return &ffi_type_uint64; if (obj == ffi->size_t_obj) { if (sizeof(size_t) == 8) return &ffi_type_uint64; else if (sizeof(size_t) == 4) return &ffi_type_uint32; else abort(); } if (obj == ffi->char_pointer_obj) return &ffi_type_pointer; if (obj == ffi->pointer_obj) return &ffi_type_pointer; if (obj_instance_of(obj, ffi->struct_obj)) { Value complete = OBJECT_LOOKUP(obj, complete); VM_ASSERT(value_is_truthy(complete), "cannot use incomplete struct in ffi call") NULL; ArrayObject *members = (ArrayObject*) obj_instance_of(OBJ_OR_NULL(OBJECT_LOOKUP(obj, members)), state->shared->vcache.array_base); VM_ASSERT(members, "ffi struct members undefined!") NULL; ffi_type *str_type = malloc(sizeof(ffi_type)); *str_type = (ffi_type) { .size = 0, .alignment = 0, .type = FFI_TYPE_STRUCT, // TODO just dangle off str_type .elements = malloc(sizeof(ffi_type*) * (members->length + 1)) }; for (int i = 0; i < members->length; i++) { ffi_type *ptr = type_to_ffi_ptr(state, ffi_obj, OBJ_OR_NULL(members->ptr[i])); if (!ptr) return NULL; // recursion errored str_type->elements[i] = ptr; } str_type->elements[members->length] = NULL; return str_type; } abort(); }
H264DecoderFrame *H264DBPList::findLongTermPic(Ipp32s picNum, Ipp32s * field) { H264DecoderFrame *pCurr = m_pHead; while (pCurr) { if (pCurr->m_PictureStructureForRef >= FRM_STRUCTURE) { if ((pCurr->isLongTermRef() == 3) && (pCurr->LongTermPicNum(0) == picNum)) { return pCurr; } } else { if (pCurr->isLongTermRef(0) && (pCurr->LongTermPicNum(0) == picNum)) { *field = 0; return pCurr; } if (pCurr->isLongTermRef(1) && (pCurr->LongTermPicNum(1) == picNum)) { *field = 1; return pCurr; } } pCurr = pCurr->future(); } VM_ASSERT(false); // No match found, should not happen. return 0; } // findLongTermPic
bool H264CoeffsBuffer::UnLockInputBuffer(size_t size) { size_t lFreeSize; BufferInfo *pTemp; uint8_t *pb; // check error(s) if (NULL == m_pbFree) return false; // get free size if (m_pbFree >= m_pbBuffer + (m_lBufferSize - m_lFreeSize)) lFreeSize = m_pbBuffer + m_lBufferSize - m_pbFree; else lFreeSize = m_lFreeSize; // check free size if (lFreeSize < m_lItemSize) return false; // check used data if (size + COEFFS_BUFFER_ALIGN_VALUE + sizeof(BufferInfo) > lFreeSize) // DEBUG : should not be !!! { VM_ASSERT(false); return false; } // get new buffer info pb = align_pointer<uint8_t *> (m_pbFree + size, COEFFS_BUFFER_ALIGN_VALUE); pTemp = reinterpret_cast<BufferInfo *> (pb); size += COEFFS_BUFFER_ALIGN_VALUE + sizeof(BufferInfo); // fill buffer info pTemp->m_Size = size; pTemp->m_pPointer = m_pbFree; pTemp->m_pNext = 0; // add sample to end of queue if (m_pBuffers) { BufferInfo *pWork = m_pBuffers; while (pWork->m_pNext) pWork = pWork->m_pNext; pWork->m_pNext = pTemp; } else m_pBuffers = pTemp; // update variable(s) m_pbFree += size; if (m_pbBuffer + m_lBufferSize == m_pbFree) m_pbFree = m_pbBuffer; m_lFreeSize -= size; return true; } // bool H264CoeffsBuffer::UnLockInputBuffer(size_t size)
mfxStatus MfxCriticalErrorHandler::ReturningCriticalStatus() { VM_ASSERT(m_CriticalErrorStatus != MFX_ERR_NONE); m_CriticalErrorReportedAtLeastOnce = true; if (m_CriticalErrorStatus == MFX_ERR_NONE) m_CriticalErrorStatus = MFX_ERR_UNKNOWN; return m_CriticalErrorStatus; }
static void ffi_ptr_add(VMState *state, CallInfo *info) { VM_ASSERT(info->args_len == 1, "wrong arity: expected 1, got %i", info->args_len); Object *pointer_base = state->shared->vcache.pointer_base; Object *thisptr = OBJ_OR_NULL(load_arg(state->frame, info->this_arg)); VM_ASSERT(thisptr && thisptr->parent == pointer_base, "internal error"); PointerObject *thisptr_obj = (PointerObject*) thisptr; void *ptr = (void*) thisptr_obj->ptr; int elemsize = 1; Value target_type = OBJECT_LOOKUP(thisptr, target_type); if (!IS_NULL(target_type)) { VM_ASSERT(IS_OBJ(target_type), "target type must be ffi type"); Value sizeof_val = OBJECT_LOOKUP(AS_OBJ(target_type), sizeof); VM_ASSERT(IS_INT(sizeof_val), "internal error: sizeof wrong type or undefined"); elemsize = AS_INT(sizeof_val); }
bool ffi_pointer_write(VMState *state, Object *type, void *ptr, Value val) { ValueCache *vcache = &state->shared->vcache; Object *string_base = vcache->string_base; FFIObject *ffi = (FFIObject*) vcache->ffi_obj; if (type == ffi->float_obj) { if (IS_FLOAT(val)) *(float*) ptr = AS_FLOAT(val); else if (IS_INT(val)) *(float*) ptr = AS_INT(val); else { VM_ASSERT(false, "invalid value for float type") false; } return true; } else { Object *c_type_obj = AS_OBJ(OBJECT_LOOKUP(type, c_type)); StringObject *c_type = (StringObject*) obj_instance_of(c_type_obj, string_base); assert(c_type); VM_ASSERT(false, "unhandled pointer write type: %s", c_type->value) false; } }
void RefCounter::DecrementReference() { m_refCounter--; VM_ASSERT(m_refCounter >= 0); if (!m_refCounter) { Free(); } }
void VM::callFunction(State *state, Object *context, UserFunction *function, Object **arguments, size_t count) { addFrame(state, function->m_slots, function->m_fastSlots); CallFrame *frame = state->m_frame; frame->m_function = function; frame->m_slots[1] = context; GC::addRoots(state, frame->m_slots, frame->m_count, &frame->m_root); if (frame->m_function->m_hasVariadicTail) VM_ASSERT(count >= frame->m_function->m_arity, "arity violation in call"); else VM_ASSERT(count == frame->m_function->m_arity, "arity violation in call"); // TODO: check if this is correct for the context for (size_t i = 0; i < function->m_arity; i++) frame->m_slots[i + 2] = arguments[i]; VM_ASSERT(frame->m_function->m_body.m_count, "invalid function"); frame->m_instructions = frame->m_function->m_body.m_instructions; }
/////////////////////////////////////////////////////////////////////////////// // freeOldestShortTermRef // Marks the oldest (having smallest FrameNumWrap) short-term reference frame // as not used as reference frame. /////////////////////////////////////////////////////////////////////////////// H264DecoderFrame * H264DBPList::freeOldestShortTermRef() { H264DecoderFrame *pOldest = findOldestShortTermRef(); VM_ASSERT(pOldest != NULL); // Should not have been called if no short-term refs if (pOldest) { pOldest->unSetisShortTermRef(0); pOldest->unSetisShortTermRef(1); } return pOldest; } // freeOldestShortTermRef
static void ffi_ptr_index_assign_fn(VMState *state, CallInfo *info) { VM_ASSERT(info->args_len == 2, "wrong arity: expected 2, got %i", info->args_len); Object *pointer_base = state->shared->vcache.pointer_base; Object *thisptr = OBJ_OR_NULL(load_arg(state->frame, info->this_arg)); VM_ASSERT(thisptr && thisptr->parent == pointer_base, "invalid pointer index write on non-pointer object"); PointerObject *thisptr_obj = (PointerObject*) thisptr; Object *ffi_type_obj = AS_OBJ(OBJECT_LOOKUP(thisptr, target_type)); VM_ASSERT(ffi_type_obj, "cannot assign index on untyped pointer!"); Value offs_val = load_arg(state->frame, INFO_ARGS_PTR(info)[0]); VM_ASSERT(IS_INT(offs_val), "offset must be integer"); int offs = AS_INT(offs_val); Value sizeof_val = OBJECT_LOOKUP(ffi_type_obj, sizeof); VM_ASSERT(IS_INT(sizeof_val), "internal error: sizeof wrong type or undefined"); int elemsize = AS_INT(sizeof_val); char *offset_ptr = (char*) thisptr_obj->ptr + elemsize * offs; bool res = ffi_pointer_write(state, ffi_type_obj, (void*) offset_ptr, load_arg(state->frame, INFO_ARGS_PTR(info)[1])); if (!res) return; }
static inline void args_extend(struct args_info *args, const int min_argc) { int i; if (args->rest) { args->rest = rb_ary_dup(args->rest); VM_ASSERT(args->rest_index == 0); for (i=args->argc + RARRAY_LENINT(args->rest); i<min_argc; i++) { rb_ary_push(args->rest, Qnil); } } else { for (i=args->argc; i<min_argc; i++) { args->argv[args->argc++] = Qnil; } } }
static VALUE args_pop_keyword_hash(struct args_info *args, VALUE *kw_hash_ptr, rb_thread_t *th) { VALUE rest_hash; if (args->rest == Qfalse) { from_argv: VM_ASSERT(args->argc > 0); *kw_hash_ptr = args->argv[args->argc-1]; if (keyword_hash_p(kw_hash_ptr, &rest_hash, th)) { if (rest_hash) { args->argv[args->argc-1] = rest_hash; } else { args->argc--; return TRUE; } } } else { long len = RARRAY_LEN(args->rest); if (len > 0) { *kw_hash_ptr = RARRAY_AREF(args->rest, len - 1); if (keyword_hash_p(kw_hash_ptr, &rest_hash, th)) { if (rest_hash) { RARRAY_ASET(args->rest, len - 1, rest_hash); } else { args->rest = rb_ary_dup(args->rest); rb_ary_pop(args->rest); return TRUE; } } } else { goto from_argv; } } return FALSE; }
static inline void args_reduce(struct args_info *args, int over_argc) { if (args->rest) { const long len = RARRAY_LEN(args->rest); if (len > over_argc) { args->rest = rb_ary_dup(args->rest); rb_ary_resize(args->rest, len - over_argc); return; } else { args->rest = Qfalse; over_argc -= len; } } VM_ASSERT(args->argc >= over_argc); args->argc -= over_argc; }
void GetMQUANT(VC1Context* pContext) { Ipp32s z; VC1PictureLayerHeader* picLayerHeader = pContext->m_picLayerHeader; Ipp32u MQUANT = picLayerHeader->PQUANT; Ipp32u HALFQP = picLayerHeader->HALFQP; if (picLayerHeader->m_PQuant_mode==VC1_ALTPQUANT_MB_LEVEL) { VC1_GET_BITS(1,z ); MQUANT= (z)? picLayerHeader->m_AltPQuant: picLayerHeader->PQUANT; } else { VM_ASSERT(picLayerHeader->m_PQuant_mode==VC1_ALTPQUANT_ANY_VALUE); VC1_GET_BITS(3,z); HALFQP = 0; if (z!=7) { MQUANT = picLayerHeader->PQUANT + z; } else { VC1_GET_BITS(5,z); MQUANT=z; } }//m_DQBILevel==0 if ((MQUANT == picLayerHeader->m_AltPQuant)) HALFQP=0; pContext->CurrDC->DCStepSize = GetDCStepSize(MQUANT); pContext->CurrDC->DoubleQuant = MQUANT *2 + HALFQP; }
UMC::Status VC1BitRateControl::CheckFrameCompression(ePType picType, Ipp32u currSize) { UMC::Status UMCSts = UMC::UMC_OK; Ipp32s Sts = 0; Ipp32s i = 0; VM_ASSERT(currSize > 0); if(currSize == 0) { return UMC::UMC_ERR_INVALID_PARAMS; } m_currSize = currSize; #ifdef BRC_TEST if(BRCFileSizeTest.RES_File) fprintf(BRCFileSizeTest.RES_File, "%d,", currSize); #endif //check HRD status for(i = 0; i < m_LBucketNum; i++) { Sts = m_HRD[i]->CheckBuffer(m_currSize); UMCSts |= HandleHRDResult(Sts); } #ifdef VC1_HRD_DEBUG // printf("CheckBuffer Sts = %d\n", Sts); #endif // UMCSts = UMC::UMC_OK; UMCSts = m_BRC->CheckFrameCompression(picType, m_currSize, UMCSts); return UMCSts; }
JCOLOR MJPEGVideoDecoderBaseMFX::GetColorType() { JCOLOR color = JC_UNKNOWN; switch(m_decBase->m_jpeg_color) { case JC_UNKNOWN: color = JC_UNKNOWN; break; case JC_GRAY: color = JC_GRAY; break; case JC_YCBCR: color = JC_YCBCR; break; case JC_RGB: color = JC_RGB; break; default: VM_ASSERT(false); break; } return color; }
void MJPEGVideoDecoderBaseMFX::SetFrameAllocator(FrameAllocator * frameAllocator) { VM_ASSERT(frameAllocator); m_frameAllocator = frameAllocator; }
Ipp32s H264SegmentDecoder::GetColocatedLocation(H264DecoderFrame *pRefFrame, Ipp32s Field, Ipp32s &block, Ipp32s *scale) { Ipp32s location = -1; Ipp32u cur_pic_struct = m_pCurrentFrame->m_PictureStructureForDec; Ipp32u ref_pic_struct = pRefFrame->m_PictureStructureForDec; Ipp32s xCol = block & 3; Ipp32s yCol = block - xCol; if (cur_pic_struct==FRM_STRUCTURE && ref_pic_struct==FRM_STRUCTURE) { if (scale) *scale = 0; return m_CurMBAddr; } else if (cur_pic_struct==AFRM_STRUCTURE && ref_pic_struct==AFRM_STRUCTURE) { Ipp32s preColMBAddr=m_CurMBAddr; H264DecoderMacroblockGlobalInfo *preColMB = &pRefFrame->m_mbinfo.mbs[preColMBAddr]; Ipp32s cur_mbfdf = pGetMBFieldDecodingFlag(m_cur_mb.GlobalMacroblockInfo); Ipp32s ref_mbfdf = pGetMBFieldDecodingFlag(preColMB); if (cur_mbfdf == ref_mbfdf) { if (scale) *scale = 0; return m_CurMBAddr; } else if (cur_mbfdf > ref_mbfdf) //current - field reference - frame { if ((preColMBAddr & 1)) { preColMBAddr-=1;//get pair if (yCol >= 8) preColMBAddr += 1;//get pair again } else { if (yCol >= 8) preColMBAddr += 1;//get pair } yCol *= 2; yCol &= 15; if (scale) *scale = 1; } else { Ipp32s curPOC = m_pCurrentFrame->PicOrderCnt(0,3); Ipp32s topPOC = pRefFrame->PicOrderCnt(0,1); Ipp32s bottomPOC = pRefFrame->PicOrderCnt(1,1); preColMBAddr &= -2; // == (preColMBAddr/2)*2; if (abs(topPOC - curPOC) >= abs(bottomPOC - curPOC)) preColMBAddr += 1; yCol = (m_CurMBAddr & 1)*8 + 4*(yCol/8); if (scale) *scale = -1; } block = yCol + xCol; return preColMBAddr; } else if (cur_pic_struct==FLD_STRUCTURE && ref_pic_struct==FLD_STRUCTURE) { if (scale) *scale = 0; Ipp32s RefField = Field; if(RefField > m_field_index) { return (m_CurMBAddr + m_pCurrentFrame->totalMBs); } return RefField < m_field_index ? (m_CurMBAddr - m_pCurrentFrame->totalMBs) : m_CurMBAddr; } else if (cur_pic_struct == FLD_STRUCTURE && ref_pic_struct == FRM_STRUCTURE) { Ipp32u PicWidthInMbs = mb_width; Ipp32u CurrMbAddr = m_field_index ? m_CurMBAddr - m_pCurrentFrame->totalMBs : m_CurMBAddr; if(scale) *scale = 1; yCol = ((2*yCol)&15); block = yCol+xCol; return 2*PicWidthInMbs*(CurrMbAddr/PicWidthInMbs) + (CurrMbAddr%PicWidthInMbs) + PicWidthInMbs*(yCol/8); } else if (cur_pic_struct == FRM_STRUCTURE && ref_pic_struct == FLD_STRUCTURE) { if (scale) *scale=-1; Ipp32u PicWidthInMbs = mb_width; Ipp32u CurrMbAddr = m_CurMBAddr; yCol = 8*((CurrMbAddr/PicWidthInMbs)&1) + 4 * (yCol/8); block = yCol+xCol; Ipp32s curPOC = m_pCurrentFrame->PicOrderCnt(0,3); Ipp32s topPOC = pRefFrame->PicOrderCnt(pRefFrame->GetNumberByParity(0), 1); Ipp32s bottomPOC = pRefFrame->PicOrderCnt(pRefFrame->GetNumberByParity(1), 1); Ipp32s add = 0; if (abs(curPOC - topPOC) >= abs(curPOC - bottomPOC)) { add = pRefFrame->totalMBs; } return (PicWidthInMbs*(CurrMbAddr/(2*PicWidthInMbs))+(CurrMbAddr%PicWidthInMbs)) + add; } else if (cur_pic_struct == FLD_STRUCTURE && ref_pic_struct == AFRM_STRUCTURE) { Ipp32u CurrMbAddr = m_CurMBAddr; if (m_field_index) CurrMbAddr -= m_pCurrentFrame->totalMBs; Ipp32s bottom_field_flag = m_field_index; Ipp32s preColMBAddr = 2*CurrMbAddr; H264DecoderMacroblockGlobalInfo *preColMB = &pRefFrame->m_mbinfo.mbs[preColMBAddr]; Ipp32s col_mbfdf = pGetMBFieldDecodingFlag(preColMB); if (!col_mbfdf) { if (yCol >= 8) preColMBAddr += 1; yCol = ((2*yCol)&15); if(scale) *scale=1; } else { if (bottom_field_flag) preColMBAddr += 1; if(scale) *scale=0; } block = yCol + xCol; return preColMBAddr; } else if (cur_pic_struct == AFRM_STRUCTURE && ref_pic_struct == FLD_STRUCTURE) { Ipp32u CurrMbAddr = m_CurMBAddr; Ipp32s preColMBAddr = CurrMbAddr; Ipp32s cur_mbfdf = pGetMBFieldDecodingFlag(m_cur_mb.GlobalMacroblockInfo); Ipp32s cur_mbbf = (m_CurMBAddr & 1); Ipp32s curPOC = m_pCurrentFrame->PicOrderCnt(0,3); Ipp32s topPOC = pRefFrame->PicOrderCnt(pRefFrame->GetNumberByParity(0), 1); Ipp32s bottomPOC = pRefFrame->PicOrderCnt(pRefFrame->GetNumberByParity(1), 1); Ipp32s bottom_field_flag = cur_mbfdf ? cur_mbbf : abs(curPOC - topPOC) >= abs(curPOC - bottomPOC); if (cur_mbbf) preColMBAddr-=1; preColMBAddr = preColMBAddr/2; if (!cur_mbfdf) { yCol = 8*cur_mbbf + 4*(yCol/8); if (scale) *scale = -1; } else { if(scale) *scale = 0; } block = yCol + xCol; VM_ASSERT(preColMBAddr +(bottom_field_flag)*pRefFrame->totalMBs < m_pCurrentFrame->totalMBs); return preColMBAddr + (bottom_field_flag)*pRefFrame->totalMBs; } else // ARFM and FRM it's non-standard case. { VM_ASSERT(0); Ipp32s preColMBAddr=m_CurMBAddr; H264DecoderMacroblockGlobalInfo *preColMB = &pRefFrame->m_mbinfo.mbs[preColMBAddr]; Ipp32s cur_mbfdf = pGetMBFieldDecodingFlag(m_cur_mb.GlobalMacroblockInfo); Ipp32s ref_mbfdf = pGetMBFieldDecodingFlag(preColMB); if (cur_mbfdf == ref_mbfdf) { if (scale) *scale = 0; return m_CurMBAddr; } else if (cur_mbfdf > ref_mbfdf) //current - field reference - frame { if ((preColMBAddr & 1)) { preColMBAddr-=1;//get pair if (yCol >= 8) preColMBAddr += 1;//get pair again } else { if (yCol >= 8) preColMBAddr += 1;//get pair } yCol *= 2; yCol &= 15; if (scale) *scale = 1; } else { Ipp32s curPOC = m_pCurrentFrame->PicOrderCnt(0,3); Ipp32s topPOC = pRefFrame->PicOrderCnt(0,1); Ipp32s bottomPOC = pRefFrame->PicOrderCnt(1,1); preColMBAddr &= -2; // == (preColMBAddr/2)*2; if (abs(topPOC - curPOC) >= abs(bottomPOC - curPOC)) preColMBAddr += 1; yCol = (m_CurMBAddr & 1)*8 + 4*(yCol/8); if (scale) *scale = -1; } block = yCol + xCol; location = preColMBAddr; } return location; } // Ipp32s H264SegmentDecoder::GetColocatedLocation(DecodedFrame *pRefFrame, Ipp8u Field, Ipp32s &block, Ipp8s *scale)
ChromaType MJPEGVideoDecoderBaseMFX::GetChromaType() { /* 0:YUV400 (grayscale image) Y: h=1 v=1, 1:YUV420 Y: h=2 v=2, Cb/Cr: h=1 v=1 2:YUV422H_2Y Y: h=2 v=1, Cb/Cr: h=1 v=1 3:YUV444 Y: h=1 v=1, Cb/Cr: h=1 v=1 4:YUV411 Y: h=4 v=1, Cb/Cr: h=1 v=1 5:YUV422V_2Y Y: h=1 v=2, Cb/Cr: h=1 v=1 6:YUV422H_4Y Y: h=2 v=2, Cb/Cr: h=1 v=2 7:YUV422V_4Y Y: h=2 v=2, Cb/Cr: h=2 v=1 */ if (m_decBase->m_jpeg_ncomp == 1) { return CHROMA_TYPE_YUV400; } ChromaType type = CHROMA_TYPE_YUV400; switch(m_decBase->m_ccomp[0].m_hsampling) { case 1: // YUV422V_2Y, YUV444 if (m_decBase->m_ccomp[0].m_vsampling == 1) // YUV444 { if (m_decBase->m_jpeg_color == JC_YCBCR) type = CHROMA_TYPE_YUV444; else if (m_decBase->m_jpeg_color == JC_RGB) type = CHROMA_TYPE_RGB; else VM_ASSERT(false); } else { VM_ASSERT((m_decBase->m_ccomp[0].m_vsampling == 2) && (m_decBase->m_ccomp[1].m_hsampling == 1)); type = CHROMA_TYPE_YUV422V_2Y; // YUV422V_2Y } break; case 2: // YUV420, YUV422H_2Y, YUV422H_4Y, YUV422V_4Y if (m_decBase->m_ccomp[0].m_vsampling == 1) { VM_ASSERT(m_decBase->m_ccomp[1].m_vsampling == 1 && m_decBase->m_ccomp[1].m_hsampling == 1); type = CHROMA_TYPE_YUV422H_2Y; // YUV422H_2Y } else { VM_ASSERT(m_decBase->m_ccomp[0].m_vsampling == 2); if (m_decBase->m_ccomp[1].m_hsampling == 1 && m_decBase->m_ccomp[1].m_vsampling == 1) type = CHROMA_TYPE_YUV420; // YUV420; else type = (m_decBase->m_ccomp[1].m_hsampling == 1) ? CHROMA_TYPE_YUV422H_4Y : CHROMA_TYPE_YUV422V_4Y; // YUV422H_4Y, YUV422V_4Y } break; case 4: // YUV411 VM_ASSERT(m_decBase->m_ccomp[0].m_vsampling == 1); type = CHROMA_TYPE_YUV411; break; default: VM_ASSERT(false); break; } return type; }
// MediaSDK DECODE_QueryIOSurf API function mfxStatus VideoDECODEH265::QueryIOSurf(VideoCORE *core, mfxVideoParam *par, mfxFrameAllocRequest *request) { MFX_AUTO_LTRACE(MFX_TRACE_LEVEL_API, "VideoDECODEH265::QueryIOSurf"); MFX_CHECK_NULL_PTR2(par, request); eMFXPlatform platform = MFX_Utility::GetPlatform_H265(core, par); eMFXHWType type = MFX_HW_UNKNOWN; if (platform == MFX_PLATFORM_HARDWARE) { type = core->GetHWType(); } mfxVideoParam params; params = *par; bool isNeedChangeVideoParamWarning = IsNeedChangeVideoParam(¶ms); if (!(par->IOPattern & MFX_IOPATTERN_OUT_VIDEO_MEMORY) && !(par->IOPattern & MFX_IOPATTERN_OUT_SYSTEM_MEMORY) && !(par->IOPattern & MFX_IOPATTERN_OUT_OPAQUE_MEMORY)) return MFX_ERR_INVALID_VIDEO_PARAM; if ((par->IOPattern & MFX_IOPATTERN_OUT_VIDEO_MEMORY) && (par->IOPattern & MFX_IOPATTERN_OUT_SYSTEM_MEMORY)) return MFX_ERR_INVALID_VIDEO_PARAM; if ((par->IOPattern & MFX_IOPATTERN_OUT_OPAQUE_MEMORY) && (par->IOPattern & MFX_IOPATTERN_OUT_SYSTEM_MEMORY)) return MFX_ERR_INVALID_VIDEO_PARAM; if ((par->IOPattern & MFX_IOPATTERN_OUT_OPAQUE_MEMORY) && (par->IOPattern & MFX_IOPATTERN_OUT_VIDEO_MEMORY)) return MFX_ERR_INVALID_VIDEO_PARAM; int32_t isInternalManaging = (MFX_PLATFORM_SOFTWARE == platform) ? (params.IOPattern & MFX_IOPATTERN_OUT_VIDEO_MEMORY) : (params.IOPattern & MFX_IOPATTERN_OUT_SYSTEM_MEMORY); mfxStatus sts = QueryIOSurfInternal(platform, type, ¶ms, request); if (sts != MFX_ERR_NONE) return sts; if (isInternalManaging) { request->NumFrameSuggested = request->NumFrameMin = (mfxU16)CalculateAsyncDepth(platform, par); if (MFX_PLATFORM_SOFTWARE == platform) request->Type = MFX_MEMTYPE_DXVA2_DECODER_TARGET | MFX_MEMTYPE_FROM_DECODE; else request->Type = MFX_MEMTYPE_SYSTEM_MEMORY | MFX_MEMTYPE_FROM_DECODE; } if (par->IOPattern & MFX_IOPATTERN_OUT_OPAQUE_MEMORY) { request->Type |= MFX_MEMTYPE_OPAQUE_FRAME; } else { request->Type |= MFX_MEMTYPE_EXTERNAL_FRAME; } if (platform != core->GetPlatformType()) { VM_ASSERT(platform == MFX_PLATFORM_SOFTWARE); return MFX_ERR_UNSUPPORTED; } if (isNeedChangeVideoParamWarning) { return MFX_WRN_INCOMPATIBLE_VIDEO_PARAM; } return MFX_ERR_NONE; }
void VC1BitRateControl::GetAllHRDParams(VC1_HRD_PARAMS* param) { VC1_hrd_OutData hrdParams; Ipp32s i = 0; Ipp32s j = 0; Ipp32s BufferSize[32]; Ipp32s Fullness[32]; Ipp32s Rate[32]; Ipp32s rate_exponent = 0;; Ipp32s buffer_size_exponent = 0; Ipp32s temp = 0; param->HRD_NUM_LEAKY_BUCKETS = m_LBucketNum; if(m_LBucketNum == 0) return; for(i = 0; i < m_LBucketNum; i++) { m_HRD[i]->GetHRDParams(&hrdParams); Fullness[i] = hrdParams.hrd_fullness; BufferSize[i] = hrdParams.hrd_buffer; Rate[i] = hrdParams.hrd_max_rate; } rate_exponent = GetHRD_Rate(Rate); buffer_size_exponent = GetHRD_Buffer(BufferSize); param->BIT_RATE_EXPONENT = rate_exponent - 6; VM_ASSERT (param->BIT_RATE_EXPONENT > 5); VM_ASSERT (param->BIT_RATE_EXPONENT < 22); param->BUFFER_SIZE_EXPONENT = buffer_size_exponent - 4; VM_ASSERT(param->BUFFER_SIZE_EXPONENT > 3); VM_ASSERT(param->BUFFER_SIZE_EXPONENT < 20); for(i = 0; i < m_LBucketNum; i++) { Rate[i] = Rate[i]>>rate_exponent; BufferSize[i] = BufferSize[i]>>buffer_size_exponent; } //Sort data for(i = 0; i < m_LBucketNum - 1; i++) for(j = i; j < m_LBucketNum - 1; j++) { if(Rate[i] > Rate[i+1]) { temp = Rate[i]; Rate[i] = Rate[i+1]; Rate[i+1] = temp; temp = BufferSize[i]; BufferSize[i] = BufferSize[i+1]; BufferSize[i+1] = temp; temp = Fullness[i]; Fullness[i] = Fullness[i+1]; Fullness[i+1] = temp; } } for(i = 0; i < m_LBucketNum; i++) { param->HRD_RATE[i] = Rate[i]; param->HRD_BUFFER[i] = BufferSize[i] - 1; param->HRD_FULLNESS[i] = Fullness[i] - 1; } }
// Reset decoder with new parameters mfxStatus VideoDECODEH265::Reset(mfxVideoParam *par) { UMC::AutomaticUMCMutex guard(m_mGuard); if (!m_isInit) return MFX_ERR_NOT_INITIALIZED; MFX_CHECK_NULL_PTR1(par); eMFXHWType type = MFX_HW_UNKNOWN; if (m_platform == MFX_PLATFORM_HARDWARE) { type = m_core->GetHWType(); } eMFXPlatform platform = MFX_Utility::GetPlatform_H265(m_core, par); if (CheckVideoParamDecoders(par, m_core->IsExternalFrameAllocator(), type) < MFX_ERR_NONE) return MFX_ERR_INVALID_VIDEO_PARAM; if (!MFX_Utility::CheckVideoParam_H265(par, type)) return MFX_ERR_INVALID_VIDEO_PARAM; if (!IsSameVideoParam(par, &m_vInitPar, type)) return MFX_ERR_INCOMPATIBLE_VIDEO_PARAM; if (m_platform != platform) { return MFX_ERR_INCOMPATIBLE_VIDEO_PARAM; } m_pH265VideoDecoder->Reset(); if (m_FrameAllocator->Reset() != UMC::UMC_OK) { return MFX_ERR_MEMORY_ALLOC; } m_frameOrder = (mfxU16)MFX_FRAMEORDER_UNKNOWN; m_isFirstRun = true; memset(&m_stat, 0, sizeof(m_stat)); m_vFirstPar = *par; bool isNeedChangeVideoParamWarning = IsNeedChangeVideoParam(&m_vFirstPar); m_vPar = m_vFirstPar; m_vPar.CreateExtendedBuffer(MFX_EXTBUFF_VIDEO_SIGNAL_INFO); m_vPar.CreateExtendedBuffer(MFX_EXTBUFF_CODING_OPTION_SPSPPS); m_vPar.CreateExtendedBuffer(MFX_EXTBUFF_HEVC_PARAM); m_vPar.mfx.NumThread = (mfxU16)CalculateNumThread(par, m_platform); m_pH265VideoDecoder->SetVideoParams(&m_vFirstPar); if (m_platform != m_core->GetPlatformType()) { VM_ASSERT(m_platform == MFX_PLATFORM_SOFTWARE); return MFX_ERR_UNSUPPORTED; } if (isNeedChangeVideoParamWarning) { return MFX_WRN_INCOMPATIBLE_VIDEO_PARAM; } return MFX_ERR_NONE; }
// Initialize decoder instance mfxStatus VideoDECODEH265::Init(mfxVideoParam *par) { MFX_AUTO_LTRACE(MFX_TRACE_LEVEL_API, "VideoDECODEH265::Init"); UMC::AutomaticUMCMutex guard(m_mGuard); if (m_isInit) return MFX_ERR_UNDEFINED_BEHAVIOR; MFX_CHECK_NULL_PTR1(par); m_platform = MFX_Utility::GetPlatform_H265(m_core, par); eMFXHWType type = MFX_HW_UNKNOWN; if (m_platform == MFX_PLATFORM_HARDWARE) { type = m_core->GetHWType(); } if (CheckVideoParamDecoders(par, m_core->IsExternalFrameAllocator(), type) < MFX_ERR_NONE) return MFX_ERR_INVALID_VIDEO_PARAM; if (!MFX_Utility::CheckVideoParam_H265(par, type)) return MFX_ERR_INVALID_VIDEO_PARAM; m_vInitPar = *par; m_vFirstPar = *par; m_vFirstPar.mfx.NumThread = 0; bool isNeedChangeVideoParamWarning = IsNeedChangeVideoParam(&m_vFirstPar); m_vPar = m_vFirstPar; m_vPar.CreateExtendedBuffer(MFX_EXTBUFF_VIDEO_SIGNAL_INFO); m_vPar.CreateExtendedBuffer(MFX_EXTBUFF_CODING_OPTION_SPSPPS); m_vPar.CreateExtendedBuffer(MFX_EXTBUFF_HEVC_PARAM); mfxU32 asyncDepth = CalculateAsyncDepth(m_platform, par); m_vPar.mfx.NumThread = (mfxU16)CalculateNumThread(par, m_platform); if (MFX_PLATFORM_SOFTWARE == m_platform) { return MFX_ERR_UNSUPPORTED; } else { m_useDelayedDisplay = ENABLE_DELAYED_DISPLAY_MODE != 0 && IsNeedToUseHWBuffering(m_core->GetHWType()) && (asyncDepth != 1); bool useBigSurfacePoolWA = MFX_Utility::IsBugSurfacePoolApplicable(type, par); m_pH265VideoDecoder.reset(useBigSurfacePoolWA ? new VATaskSupplierBigSurfacePool<VATaskSupplier>() : new VATaskSupplier()); // HW m_FrameAllocator.reset(new mfx_UMC_FrameAllocator_D3D()); } int32_t useInternal = (MFX_PLATFORM_SOFTWARE == m_platform) ? (m_vPar.IOPattern & MFX_IOPATTERN_OUT_VIDEO_MEMORY) : (m_vPar.IOPattern & MFX_IOPATTERN_OUT_SYSTEM_MEMORY); if (m_vPar.IOPattern & MFX_IOPATTERN_OUT_OPAQUE_MEMORY) { mfxExtOpaqueSurfaceAlloc *pOpaqAlloc = (mfxExtOpaqueSurfaceAlloc *)GetExtendedBuffer(par->ExtParam, par->NumExtParam, MFX_EXTBUFF_OPAQUE_SURFACE_ALLOCATION); if (!pOpaqAlloc) return MFX_ERR_INVALID_VIDEO_PARAM; useInternal = (m_platform == MFX_PLATFORM_SOFTWARE) ? !(pOpaqAlloc->Out.Type & MFX_MEMTYPE_SYSTEM_MEMORY) : (pOpaqAlloc->Out.Type & MFX_MEMTYPE_SYSTEM_MEMORY); } // allocate memory mfxFrameAllocRequest request; mfxFrameAllocRequest request_internal; memset(&request, 0, sizeof(request)); memset(&m_response, 0, sizeof(m_response)); memset(&m_response_alien, 0, sizeof(m_response_alien)); m_isOpaq = false; mfxStatus mfxSts = QueryIOSurfInternal(m_platform, type, &m_vPar, &request); if (mfxSts != MFX_ERR_NONE) return mfxSts; if (useInternal) request.Type |= MFX_MEMTYPE_INTERNAL_FRAME ; else request.Type |= MFX_MEMTYPE_EXTERNAL_FRAME; request_internal = request; // allocates external surfaces: bool mapOpaq = true; mfxExtOpaqueSurfaceAlloc *pOpqAlloc = 0; mfxSts = UpdateAllocRequest(par, &request, pOpqAlloc, mapOpaq); if (mfxSts < MFX_ERR_NONE) return mfxSts; if (m_isOpaq && !m_core->IsCompatibleForOpaq()) return MFX_ERR_UNDEFINED_BEHAVIOR; if (mapOpaq) { mfxSts = m_core->AllocFrames(&request, &m_response, pOpqAlloc->Out.Surfaces, pOpqAlloc->Out.NumSurface); } else { if (m_platform != MFX_PLATFORM_SOFTWARE && !useInternal) { request.AllocId = par->AllocId; mfxSts = m_core->AllocFrames(&request, &m_response, false); } } if (mfxSts < MFX_ERR_NONE) return mfxSts; // allocates internal surfaces: if (useInternal) { m_response_alien = m_response; m_FrameAllocator->SetExternalFramesResponse(&m_response_alien); request = request_internal; mfxSts = m_core->AllocFrames(&request_internal, &m_response, true); if (mfxSts < MFX_ERR_NONE) return mfxSts; } else { m_FrameAllocator->SetExternalFramesResponse(&m_response); } if (m_platform != MFX_PLATFORM_SOFTWARE) { mfxSts = m_core->CreateVA(&m_vFirstPar, &request, &m_response, m_FrameAllocator.get()); if (mfxSts < MFX_ERR_NONE) return mfxSts; } UMC::Status umcSts = m_FrameAllocator->InitMfx(0, m_core, &m_vFirstPar, &request, &m_response, !useInternal, m_platform == MFX_PLATFORM_SOFTWARE); if (umcSts != UMC::UMC_OK) return MFX_ERR_MEMORY_ALLOC; umcSts = m_MemoryAllocator.InitMem(0, m_core); if (umcSts != UMC::UMC_OK) return MFX_ERR_MEMORY_ALLOC; m_pH265VideoDecoder->SetFrameAllocator(m_FrameAllocator.get()); UMC::VideoDecoderParams umcVideoParams; ConvertMFXParamsToUMC(&m_vFirstPar, &umcVideoParams); umcVideoParams.numThreads = m_vPar.mfx.NumThread; umcVideoParams.info.bitrate = MFX_MAX(asyncDepth - umcVideoParams.numThreads, 0); // buffered frames if (MFX_PLATFORM_SOFTWARE != m_platform) { m_core->GetVA((mfxHDL*)&m_va, MFX_MEMTYPE_FROM_DECODE); umcVideoParams.pVideoAccelerator = m_va; static_cast<VATaskSupplier*>(m_pH265VideoDecoder.get())->SetVideoHardwareAccelerator(m_va); } umcVideoParams.lpMemoryAllocator = &m_MemoryAllocator; umcSts = m_pH265VideoDecoder->Init(&umcVideoParams); if (umcSts != UMC::UMC_OK) { return ConvertUMCStatusToMfx(umcSts); } m_isInit = true; m_frameOrder = (mfxU16)MFX_FRAMEORDER_UNKNOWN; m_isFirstRun = true; if (MFX_PLATFORM_SOFTWARE != m_platform && m_useDelayedDisplay) { static_cast<VATaskSupplier*>(m_pH265VideoDecoder.get())->SetBufferedFramesNumber(NUMBER_OF_ADDITIONAL_FRAMES); } m_pH265VideoDecoder->SetVideoParams(&m_vFirstPar); if (m_platform != m_core->GetPlatformType()) { VM_ASSERT(m_platform == MFX_PLATFORM_SOFTWARE); return MFX_ERR_UNSUPPORTED; } if (isNeedChangeVideoParamWarning) { return MFX_WRN_INCOMPATIBLE_VIDEO_PARAM; } return MFX_ERR_NONE; }
// Wait until a frame is ready to be output and set necessary surface flags mfxStatus VideoDECODEH265::DecodeFrame(mfxFrameSurface1 *surface_out, H265DecoderFrame * pFrame) { MFX_AUTO_LTRACE(MFX_TRACE_LEVEL_HOTSPOTS, "VideoDECODEH265::DecodeFrame"); MFX_CHECK_NULL_PTR1(surface_out); mfxI32 index; if (pFrame) { index = pFrame->GetFrameData()->GetFrameMID(); } else { index = m_FrameAllocator->FindSurface(surface_out, m_isOpaq); pFrame = m_pH265VideoDecoder->FindSurface((UMC::FrameMemID)index); if (!pFrame) { VM_ASSERT(false); return MFX_ERR_NOT_FOUND; } } surface_out->Data.Corrupted = 0; int32_t const error = pFrame->GetError(); if (error & UMC::ERROR_FRAME_DEVICE_FAILURE) { surface_out->Data.Corrupted |= MFX_CORRUPTION_MAJOR; if (error == UMC::UMC_ERR_GPU_HANG) return MFX_ERR_GPU_HANG; else return MFX_ERR_DEVICE_FAILED; } else { if (error & UMC::ERROR_FRAME_MINOR) surface_out->Data.Corrupted |= MFX_CORRUPTION_MINOR; if (error & UMC::ERROR_FRAME_MAJOR) surface_out->Data.Corrupted |= MFX_CORRUPTION_MAJOR; if (error & UMC::ERROR_FRAME_REFERENCE_FRAME) surface_out->Data.Corrupted |= MFX_CORRUPTION_REFERENCE_FRAME; if (error & UMC::ERROR_FRAME_DPB) surface_out->Data.Corrupted |= MFX_CORRUPTION_REFERENCE_LIST; if (error & UMC::ERROR_FRAME_RECOVERY) surface_out->Data.Corrupted |= MFX_CORRUPTION_MAJOR; if (error & UMC::ERROR_FRAME_TOP_FIELD_ABSENT) surface_out->Data.Corrupted |= MFX_CORRUPTION_ABSENT_TOP_FIELD; if (error & UMC::ERROR_FRAME_BOTTOM_FIELD_ABSENT) surface_out->Data.Corrupted |= MFX_CORRUPTION_ABSENT_BOTTOM_FIELD; } mfxStatus sts = m_FrameAllocator->PrepareToOutput(surface_out, index, &m_vPar, m_isOpaq); pFrame->setWasDisplayed(); return sts; }
// Fill up frame parameters before returning it to application void VideoDECODEH265::FillOutputSurface(mfxFrameSurface1 **surf_out, mfxFrameSurface1 *surface_work, H265DecoderFrame * pFrame) { m_stat.NumFrame++; m_stat.NumError += pFrame->GetError() ? 1 : 0; const UMC::FrameData * fd = pFrame->GetFrameData(); *surf_out = m_FrameAllocator->GetSurface(fd->GetFrameMID(), surface_work, &m_vPar); if(m_isOpaq) *surf_out = m_core->GetOpaqSurface((*surf_out)->Data.MemId); VM_ASSERT(*surf_out); mfxFrameSurface1 *surface_out = *surf_out; surface_out->Info.FrameId.TemporalId = 0; surface_out->Info.CropH = (mfxU16)(pFrame->lumaSize().height - pFrame->m_crop_bottom - pFrame->m_crop_top); surface_out->Info.CropW = (mfxU16)(pFrame->lumaSize().width - pFrame->m_crop_right - pFrame->m_crop_left); surface_out->Info.CropX = (mfxU16)(pFrame->m_crop_left); surface_out->Info.CropY = (mfxU16)(pFrame->m_crop_top); bool isShouldUpdate = !(m_vFirstPar.mfx.FrameInfo.AspectRatioH || m_vFirstPar.mfx.FrameInfo.AspectRatioW); surface_out->Info.AspectRatioH = isShouldUpdate ? (mfxU16)pFrame->m_aspect_height : m_vFirstPar.mfx.FrameInfo.AspectRatioH; surface_out->Info.AspectRatioW = isShouldUpdate ? (mfxU16)pFrame->m_aspect_width : m_vFirstPar.mfx.FrameInfo.AspectRatioW; isShouldUpdate = !(m_vFirstPar.mfx.FrameInfo.FrameRateExtD || m_vFirstPar.mfx.FrameInfo.FrameRateExtN); surface_out->Info.FrameRateExtD = isShouldUpdate ? m_vPar.mfx.FrameInfo.FrameRateExtD : m_vFirstPar.mfx.FrameInfo.FrameRateExtD; surface_out->Info.FrameRateExtN = isShouldUpdate ? m_vPar.mfx.FrameInfo.FrameRateExtN : m_vFirstPar.mfx.FrameInfo.FrameRateExtN; surface_out->Info.PicStruct = 0; switch(pFrame->m_chroma_format) { case 0: surface_out->Info.ChromaFormat = MFX_CHROMAFORMAT_YUV400; break; case 2: surface_out->Info.ChromaFormat = MFX_CHROMAFORMAT_YUV422; break; default: surface_out->Info.ChromaFormat = MFX_CHROMAFORMAT_YUV420; break; } surface_out->Info.PicStruct = UMC2MFX_PicStruct(pFrame->m_DisplayPictureStruct_H265, !!m_vPar.mfx.ExtendedPicStruct); surface_out->Data.TimeStamp = GetMfxTimeStamp(pFrame->m_dFrameTime); surface_out->Data.FrameOrder = (mfxU32)MFX_FRAMEORDER_UNKNOWN; surface_out->Data.DataFlag = (mfxU16)(pFrame->m_isOriginalPTS ? MFX_FRAMEDATA_ORIGINAL_TIMESTAMP : 0); SEI_Storer_H265 * storer = m_pH265VideoDecoder->GetSEIStorer(); if (storer) storer->SetTimestamp(pFrame); mfxExtDecodedFrameInfo* info = (mfxExtDecodedFrameInfo*)GetExtendedBuffer(surface_out->Data.ExtParam, surface_out->Data.NumExtParam, MFX_EXTBUFF_DECODED_FRAME_INFO); if (info) { switch (pFrame->m_FrameType) { case UMC::I_PICTURE: info->FrameType = MFX_FRAMETYPE_I; if (pFrame->GetAU()->m_IsIDR) info->FrameType |= MFX_FRAMETYPE_IDR; break; case UMC::P_PICTURE: info->FrameType = MFX_FRAMETYPE_P; break; case UMC::B_PICTURE: info->FrameType = MFX_FRAMETYPE_B; break; default: VM_ASSERT(!"Unknown frame type"); info->FrameType = MFX_FRAMETYPE_UNKNOWN; } if (pFrame->m_isUsedAsReference) info->FrameType |= MFX_FRAMETYPE_REF; } }
bool H264CoeffsBuffer::UnLockInputBuffer(size_t size) { size_t lFreeSize; BufferInfo *pTemp; Ipp8u *pb; #ifdef LIGHT_SYNC AutomaticUMCMutex guard(mutex); #endif // check error(s) if (NULL == m_pbFree) return false; // when no data given //if (0 == size) // even for size = 0 we should add buffer // return true; // get free size if (m_pbFree >= m_pbBuffer + (m_lBufferSize - m_lFreeSize)) lFreeSize = m_pbBuffer + m_lBufferSize - m_pbFree; else lFreeSize = m_lFreeSize; // check free size if (lFreeSize < m_lItemSize) return false; // check used data if (size + COEFFS_BUFFER_ALIGN_VALUE + sizeof(BufferInfo) > lFreeSize) // DEBUG : should not be !!! { VM_ASSERT(false); return false; } // get new buffer info pb = align_pointer<Ipp8u *> (m_pbFree + size, COEFFS_BUFFER_ALIGN_VALUE); pTemp = reinterpret_cast<BufferInfo *> (pb); size += COEFFS_BUFFER_ALIGN_VALUE + sizeof(BufferInfo); // fill buffer info pTemp->m_Size = size; pTemp->m_pPointer = m_pbFree; pTemp->m_pNext = 0; // add sample to end of queue if (m_pBuffers) { BufferInfo *pWork = m_pBuffers; while (pWork->m_pNext) pWork = pWork->m_pNext; pWork->m_pNext = pTemp; } else m_pBuffers = pTemp; // update variable(s) m_pbFree += size; if (m_pbBuffer + m_lBufferSize == m_pbFree) m_pbFree = m_pbBuffer; m_lFreeSize -= size; return true; } // bool H264CoeffsBuffer::UnLockInputBuffer(size_t size)