STDMETHODIMP CVRPresenterStreamDXVA::Present(LPBYTE *ppbPlanes, DWORD *pdwStrides, DWORD dwFlags) { LPBYTE pBuf = NULL; DWORD stride = 0; HRESULT hr = S_OK; hr = LockSurface(&pBuf , &stride); if(FAILED(hr)) return hr; DWORD srcWidth[3]; DWORD srcHeight[3]; srcWidth[0] = m_open_param.dwWidth; srcWidth[1] = srcWidth[2] = m_open_param.dwWidth>>1; srcHeight[0] = m_open_param.dwHeight; srcHeight[1] = srcHeight[2] = m_open_param.dwHeight>>1; if(m_open_param.dwFourCC == MAKE_FOURCC('Y','V','1','2')) hr = m_PrepareData.PrepareBufferYV12(pBuf, stride, ppbPlanes, pdwStrides, srcWidth, srcHeight, dwFlags, 0,0,0,m_deinterlace); else if(m_open_param.dwFourCC == MAKE_FOURCC('R','5','6','5')) { } hr = UnlockSurface(); return hr; }
static gboolean extract_resolution (GstTcamWhitebalance* self) { GstPad* pad = GST_BASE_TRANSFORM_SINK_PAD(self); GstCaps* caps = gst_pad_get_current_caps(pad); GstStructure *structure = gst_caps_get_structure (caps, 0); g_return_val_if_fail(gst_structure_get_int(structure, "width", &self->image_size.width), FALSE); g_return_val_if_fail(gst_structure_get_int(structure, "height", &self->image_size.height), FALSE); guint fourcc; if (gst_structure_get_field_type(structure, "format") == G_TYPE_STRING) { const char *string; string = gst_structure_get_string (structure, "format"); fourcc = GST_STR_FOURCC (string); } if (fourcc == MAKE_FOURCC ('g','r','b','g')) { self->pattern = GR; } else if (fourcc == MAKE_FOURCC ('r', 'g', 'g', 'b')) { self->pattern = RG; } else if (fourcc == MAKE_FOURCC ('g', 'b', 'r', 'g')) { self->pattern = GB; } else if (fourcc == MAKE_FOURCC ('b', 'g', 'g', 'r')) { self->pattern = BG; } else { GST_ERROR("Unable to determine bayer pattern."); return FALSE; } // we only handle bayer 8 bit -> 1 byte int bytes_per_pixel = 1; self->expected_buffer_size = self->image_size.height * self->image_size.width * bytes_per_pixel; self->res = find_source(GST_ELEMENT(self)); return TRUE; }
void vc_vchi_gencmd_init (VCHI_INSTANCE_T initialise_instance, VCHI_CONNECTION_T **connections, uint32_t num_connections ) { int32_t success; int i; // record the number of connections memset( &gencmd_client, 0, sizeof(GENCMD_SERVICE_T) ); gencmd_client.num_connections = (int) num_connections; success = os_semaphore_create( &gencmd_client.sema, OS_SEMAPHORE_TYPE_SUSPEND ); assert( success == 0 ); success = os_semaphore_create( &gencmd_message_available_semaphore, OS_SEMAPHORE_TYPE_BUSY_WAIT ); assert( success == 0 ); success = os_semaphore_obtain( &gencmd_message_available_semaphore ); assert( success == 0 ); for (i=0; i<gencmd_client.num_connections; i++) { // Create a 'LONG' service on the each of the connections SERVICE_CREATION_T gencmd_parameters = { MAKE_FOURCC("GCMD"), // 4cc service code connections[i], // passed in fn ptrs 0, // tx fifo size (unused) 0, // tx fifo size (unused) &gencmd_callback, // service callback &gencmd_message_available_semaphore, // callback parameter VC_FALSE, // want_unaligned_bulk_rx VC_FALSE, // want_unaligned_bulk_tx VC_FALSE // want_crc }; success = vchi_service_open( initialise_instance, &gencmd_parameters, &gencmd_client.open_handle[i] ); assert( success == 0 ); } }
/* ---------------------------------------------------------------------- * initialise host-side OpenMAX IL component service * -------------------------------------------------------------------- */ void vc_vchi_ilcs_init( VCHI_INSTANCE_T initialise_instance, VCHI_CONNECTION_T **connections, uint32_t num_connections ) { int32_t success; SERVICE_CREATION_T parameters = { MAKE_FOURCC("ILCS"), // 4cc service code connections[0], // passed in fn ptrs 0, // tx fifo size (unused) 0, // tx fifo size (unused) 0, // service callback 0 }; // callback parameter memset( &vc_ilcsg, 0, sizeof(VC_ILCS_GLOBALS_T) ); // create thread semaphore for blocking os_semaphore_create( &vc_ilcsg.component_lock, OS_SEMAPHORE_TYPE_SUSPEND ); // create semaphore for protecting wait/xid structures os_semaphore_create( &vc_ilcsg.wait_sem, OS_SEMAPHORE_TYPE_SUSPEND ); // create semaphore for correct ordering of control+bulk pairs os_semaphore_create( &vc_ilcsg.send_sem, OS_SEMAPHORE_TYPE_SUSPEND ); // open 'ILCS' service success = vchi_service_open( initialise_instance, ¶meters, &vc_ilcsg.vchi_handle ); vc_assert( success == 0 ); success = os_thread_start( &vc_ilcsg.thread, vc_ilcs_task, NULL, 4000, "ILCS_HOST" ); vc_assert( success == 0 ); }
SoundBlock DecodefromBNS(const u8 *buffer, u32 size) { SoundBlock OutBlock; memset(&OutBlock, 0, sizeof(SoundBlock)); const BNSHeader &hdr = *(BNSHeader *)buffer; if (size < sizeof hdr) return OutBlock; if (hdr.fccBNS != MAKE_FOURCC('B','N','S',' ')) return OutBlock; // Find info and data BNSInfo infoChunk; loadBNSInfo(infoChunk, buffer + hdr.infoOffset); const BNSData &dataChunk = *(const BNSData *)(buffer + hdr.dataOffset); // Check sizes if (size < hdr.size || size < hdr.infoOffset + hdr.infoSize || size < hdr.dataOffset + hdr.dataSize || hdr.infoSize < 0x60 || hdr.dataSize < sizeof dataChunk || infoChunk.size != hdr.infoSize || dataChunk.size > hdr.dataSize) return OutBlock; // Check format if (infoChunk.codecNum != 0) // Only codec i've found : 0 = ADPCM. Maybe there's also 1 and 2 for PCM 8 or 16 bits ? return OutBlock; u8 format = (u8)-1; if (infoChunk.chanCount == 1 && infoChunk.codecNum == 0) format = VOICE_MONO_16BIT; else if (infoChunk.chanCount == 2 && infoChunk.codecNum == 0) format = VOICE_STEREO_16BIT; if (format == (u8)-1) return OutBlock; u32 freq = (u32) infoChunk.freq; u32 length = 0; // Copy data if (infoChunk.codecNum == 0) { OutBlock.buffer = decodeBNS(length, infoChunk, dataChunk); if (!OutBlock.buffer) return OutBlock; } else { OutBlock.buffer = (u8*) malloc(dataChunk.size); if (!OutBlock.buffer) return OutBlock; memcpy(OutBlock.buffer, &dataChunk.data, dataChunk.size); length = dataChunk.size; } OutBlock.frequency = freq; OutBlock.format = format; OutBlock.size = length; OutBlock.loopStart = infoChunk.loopStart; OutBlock.loopEnd = infoChunk.loopEnd; OutBlock.loopFlag = infoChunk.loopFlag; return OutBlock; }
void vc_vchi_gencmd_init (VCHI_INSTANCE_T initialise_instance, VCHI_CONNECTION_T **connections, uint32_t num_connections ) { VCOS_STATUS_T status; int32_t success; int i; if (gencmd_client.initialised) return; // record the number of connections memset( &gencmd_client, 0, sizeof(GENCMD_SERVICE_T) ); gencmd_client.num_connections = (int) num_connections; status = vcos_mutex_create(&gencmd_client.lock, "HGencmd"); vcos_assert(status == VCOS_SUCCESS); status = vcos_event_create(&gencmd_client.message_available_event, "HGencmd"); vcos_assert(status == VCOS_SUCCESS); for (i=0; i<gencmd_client.num_connections; i++) { // Create a 'LONG' service on the each of the connections SERVICE_CREATION_T gencmd_parameters = { VCHI_VERSION(VC_GENCMD_VER), MAKE_FOURCC("GCMD"), // 4cc service code connections[i], // passed in fn ptrs 0, // tx fifo size (unused) 0, // tx fifo size (unused) &gencmd_callback, // service callback &gencmd_client.message_available_event, // callback parameter VC_FALSE, // want_unaligned_bulk_rx VC_FALSE, // want_unaligned_bulk_tx VC_FALSE // want_crc }; success = vchi_service_open( initialise_instance, &gencmd_parameters, &gencmd_client.open_handle[i] ); assert( success == 0 ); } gencmd_client.initialised = 1; release_gencmd_service(); }
/* ---------------------------------------------------------------------- * initialise host-side OpenMAX IL component service * -------------------------------------------------------------------- */ void vc_vchi_ilcs_init( VCHI_INSTANCE_T initialise_instance, VCHI_CONNECTION_T **connections, uint32_t num_connections ) { int32_t success; memset( &vc_ilcsg, 0, sizeof(VC_ILCS_GLOBALS_T) ); // sema_init(&vc_ilcsg.msg_prod, 0); sema_init(&vc_ilcsg.msg_cons, 1); sema_init(&vc_ilcsg.omxlog_lock, 1); vc_ilcsg.omxlog_rindex = 0; vc_ilcsg.omxlog_windex = 0; vc_ilcsg.omxlog = vmalloc(VC03_OMXLOG_MAX); memset(vc_ilcsg.omxlog, 0, VC03_OMXLOG_MAX); // create thread semaphore for blocking os_semaphore_create( &vc_ilcsg.component_lock, OS_SEMAPHORE_TYPE_SUSPEND ); os_semaphore_create( &vc_ilcsg.rxmsg_sem, OS_SEMAPHORE_TYPE_SUSPEND ); os_semaphore_obtain( &vc_ilcsg.rxmsg_sem ); // create semaphore for protecting wait/xid structures os_semaphore_create( &vc_ilcsg.wait_sem, OS_SEMAPHORE_TYPE_SUSPEND ); // open 'ILCS' service SERVICE_CREATION_T parameters = { MAKE_FOURCC("ILCS"), // 4cc service code connections[0], // passed in fn ptrs 0, // tx fifo size (unused) 0, // tx fifo size (unused) &vc_ilcs_callback, // service callback &vc_ilcsg.rxmsg_sem }; // callback parameter success = vchi_service_open( initialise_instance, ¶meters, &vc_ilcsg.vchi_handle ); assert( success == 0 ); success = os_thread_start( &vc_ilcsg.thread, vc_ilcs_task, NULL, 4000, "ILCS_HOST" ); assert( success == 0 ); }
/*********************************************************** * Name: vchi_control_service_init * * Arguments: VCHI_CONNECTION_T *connections, * const uint32_t num_connections * * Description: Routine to init the control service * * Returns: int32_t - success == 0 * ***********************************************************/ int32_t vchi_control_service_init( VCHI_CONNECTION_T **connections, const uint32_t num_connections, void **state ) { int32_t success = 0; uint32_t count = 0; CONTROL_SERVICE_INFO_T *control_info = (CONTROL_SERVICE_INFO_T *)*state; os_assert(num_connections <= VCHI_MAX_NUM_CONNECTIONS); if (!control_info) { control_info = (CONTROL_SERVICE_INFO_T *)os_malloc( VCHI_MAX_NUM_CONNECTIONS * sizeof(CONTROL_SERVICE_INFO_T), 0, "vchi:control_info" ); memset( control_info, 0,VCHI_MAX_NUM_CONNECTIONS * sizeof(CONTROL_SERVICE_INFO_T) ); for( count = 0; count < num_connections; count++ ) { #ifdef VCHI_COARSE_LOCKING os_semaphore_obtain(&connections[count]->sem); #endif // create and obtain the semaphore used to signal when we have connected success += os_semaphore_create( &control_info[count].connected_semaphore, OS_SEMAPHORE_TYPE_BUSY_WAIT ); os_assert( success == 0 ); // record the connection info control_info[count].connection = connections[count]; // create the server (this is a misnomer as the the CTRL service acts as both client and server success += (connections[count])->api->service_connect((connections[count])->state,MAKE_FOURCC("CTRL"),0,0,VC_TRUE,control_callback,&control_info[count],VC_FALSE,VC_FALSE,VC_FALSE,&control_info[count].open_handle); os_assert(success == 0); #ifdef VCHI_COARSE_LOCKING os_semaphore_release(&connections[count]->sem); #endif } // start timestamps from zero time_offset = 0; time_offset -= vchi_control_get_time(); } else { for ( count = 0; count < num_connections; count++ ) { os_assert(control_info[count].connection == connections[count]); } } // because we can have both ends of a connection running on one processor we need to send down the CONNECTION command after all // the connections have been connected for( count = 0; count < num_connections; count++ ) { #ifdef VCHI_COARSE_LOCKING os_semaphore_obtain(&connections[count]->sem); #endif // record that we have not yet handled an INIT request control_info[count].initialised = VC_FALSE; success = os_semaphore_obtain( &control_info[count].connected_semaphore ); os_assert( success == 0 ); success = vchi_control_queue_connect( &control_info[count], VC_FALSE ); os_assert(success == 0); #ifdef VCHI_COARSE_LOCKING os_semaphore_release(&connections[count]->sem); #endif } // now we must wait for the connections to have their INIT returned for( count = 0; count < num_connections; count++ ) { success = os_semaphore_obtain( &control_info[count].connected_semaphore ); os_assert( success == 0 ); success = os_semaphore_release( &control_info[count].connected_semaphore ); os_assert( success == 0 ); } *state = control_info; return success; }
dds_data load_dds_from_file(FILE *f) { dds_data ret = {}; dds_data error = {}; FileIO::fseek64(f, 0, SEEK_SET); uint32_t magic = 0; FileIO::fread(&magic, sizeof(magic), 1, f); DDS_HEADER header = {}; FileIO::fread(&header, sizeof(header), 1, f); bool dx10Header = false; DDS_HEADER_DXT10 headerDXT10 = {}; if(header.ddspf.dwFlags == DDPF_FOURCC && header.ddspf.dwFourCC == MAKE_FOURCC('D', 'X', '1', '0')) { FileIO::fread(&headerDXT10, sizeof(headerDXT10), 1, f); dx10Header = true; } ret.width = RDCMAX(1U, header.dwWidth); ret.height = RDCMAX(1U, header.dwHeight); ret.depth = RDCMAX(1U, header.dwDepth); ret.slices = dx10Header ? RDCMAX(1U, headerDXT10.arraySize) : 1; ret.mips = RDCMAX(1U, header.dwMipMapCount); uint32_t cubeFlags = DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES; if((header.dwCaps2 & cubeFlags) == cubeFlags && header.dwCaps & DDSCAPS_COMPLEX) ret.cubemap = true; if(dx10Header && headerDXT10.miscFlag & DDS_RESOURCE_MISC_TEXTURECUBE) ret.cubemap = true; if(ret.cubemap) ret.slices *= 6; if(dx10Header) { ret.format = DXGIFormat2ResourceFormat(headerDXT10.dxgiFormat); if(ret.format.type == ResourceFormatType::Undefined) { RDCWARN("Unsupported DXGI_FORMAT: %u", (uint32_t)headerDXT10.dxgiFormat); return error; } } else if(header.ddspf.dwFlags & DDPF_FOURCC) { switch(header.ddspf.dwFourCC) { case MAKE_FOURCC('D', 'X', 'T', '1'): ret.format = DXGIFormat2ResourceFormat(DXGI_FORMAT_BC1_UNORM); break; case MAKE_FOURCC('D', 'X', 'T', '3'): ret.format = DXGIFormat2ResourceFormat(DXGI_FORMAT_BC2_UNORM); break; case MAKE_FOURCC('D', 'X', 'T', '5'): ret.format = DXGIFormat2ResourceFormat(DXGI_FORMAT_BC3_UNORM); break; case MAKE_FOURCC('A', 'T', 'I', '1'): case MAKE_FOURCC('B', 'C', '4', 'U'): ret.format = DXGIFormat2ResourceFormat(DXGI_FORMAT_BC4_UNORM); break; case MAKE_FOURCC('B', 'C', '4', 'S'): ret.format = DXGIFormat2ResourceFormat(DXGI_FORMAT_BC4_SNORM); break; case MAKE_FOURCC('A', 'T', 'I', '2'): case MAKE_FOURCC('B', 'C', '5', 'U'): ret.format = DXGIFormat2ResourceFormat(DXGI_FORMAT_BC5_UNORM); break; case MAKE_FOURCC('B', 'C', '5', 'S'): ret.format = DXGIFormat2ResourceFormat(DXGI_FORMAT_BC5_SNORM); break; case MAKE_FOURCC('R', 'G', 'B', 'G'): ret.format = DXGIFormat2ResourceFormat(DXGI_FORMAT_R8G8_B8G8_UNORM); break; case MAKE_FOURCC('G', 'R', 'G', 'B'): ret.format = DXGIFormat2ResourceFormat(DXGI_FORMAT_G8R8_G8B8_UNORM); break; case 36: ret.format = DXGIFormat2ResourceFormat(DXGI_FORMAT_R16G16B16A16_UNORM); break; case 110: ret.format = DXGIFormat2ResourceFormat(DXGI_FORMAT_R16G16B16A16_SNORM); break; case 111: ret.format = DXGIFormat2ResourceFormat(DXGI_FORMAT_R16_FLOAT); break; case 112: ret.format = DXGIFormat2ResourceFormat(DXGI_FORMAT_R16G16_FLOAT); break; case 113: ret.format = DXGIFormat2ResourceFormat(DXGI_FORMAT_R16G16B16A16_FLOAT); break; case 114: ret.format = DXGIFormat2ResourceFormat(DXGI_FORMAT_R32_FLOAT); break; case 115: ret.format = DXGIFormat2ResourceFormat(DXGI_FORMAT_R32G32_FLOAT); break; case 116: ret.format = DXGIFormat2ResourceFormat(DXGI_FORMAT_R32G32B32A32_FLOAT); break; default: RDCWARN("Unsupported FourCC: %08x", header.ddspf.dwFourCC); return error; } } else { if(header.ddspf.dwRGBBitCount != 32 && header.ddspf.dwRGBBitCount != 24 && header.ddspf.dwRGBBitCount != 16 && header.ddspf.dwRGBBitCount != 8) { RDCWARN("Unsupported RGB bit count: %u", header.ddspf.dwRGBBitCount); return error; } ret.format.compByteWidth = 1; ret.format.compCount = uint8_t(header.ddspf.dwRGBBitCount / 8); ret.format.compType = CompType::UNorm; ret.format.type = ResourceFormatType::Regular; if(header.ddspf.dwBBitMask < header.ddspf.dwRBitMask) ret.format.bgraOrder = true; } uint32_t bytesPerPixel = 1; switch(ret.format.type) { case ResourceFormatType::S8: bytesPerPixel = 1; break; case ResourceFormatType::R10G10B10A2: case ResourceFormatType::R9G9B9E5: case ResourceFormatType::R11G11B10: case ResourceFormatType::D24S8: bytesPerPixel = 4; break; case ResourceFormatType::R5G6B5: case ResourceFormatType::R5G5B5A1: case ResourceFormatType::R4G4B4A4: bytesPerPixel = 2; break; case ResourceFormatType::D32S8: bytesPerPixel = 8; break; case ResourceFormatType::D16S8: case ResourceFormatType::YUV: case ResourceFormatType::R4G4: RDCERR("Unsupported file format %u", ret.format.type); return error; default: bytesPerPixel = ret.format.compCount * ret.format.compByteWidth; } bool blockFormat = false; if(ret.format.Special()) { switch(ret.format.type) { case ResourceFormatType::BC1: case ResourceFormatType::BC2: case ResourceFormatType::BC3: case ResourceFormatType::BC4: case ResourceFormatType::BC5: case ResourceFormatType::BC6: case ResourceFormatType::BC7: blockFormat = true; break; case ResourceFormatType::ETC2: case ResourceFormatType::EAC: case ResourceFormatType::ASTC: case ResourceFormatType::YUV: RDCERR("Unsupported file format, %u", ret.format.type); return error; default: break; } } ret.subsizes = new uint32_t[ret.slices * ret.mips]; ret.subdata = new byte *[ret.slices * ret.mips]; int i = 0; for(int slice = 0; slice < ret.slices; slice++) { for(int mip = 0; mip < ret.mips; mip++) { int rowlen = RDCMAX(1, ret.width >> mip); int numRows = RDCMAX(1, ret.height >> mip); int numdepths = RDCMAX(1, ret.depth >> mip); int pitch = RDCMAX(1U, rowlen * bytesPerPixel); // pitch/rows are in blocks, not pixels, for block formats. if(blockFormat) { numRows = RDCMAX(1, numRows / 4); int blockSize = (ret.format.type == ResourceFormatType::BC1 || ret.format.type == ResourceFormatType::BC4) ? 8 : 16; pitch = RDCMAX(blockSize, (((rowlen + 3) / 4)) * blockSize); } ret.subsizes[i] = numdepths * numRows * pitch; byte *bytedata = ret.subdata[i] = new byte[ret.subsizes[i]]; for(int d = 0; d < numdepths; d++) { for(int row = 0; row < numRows; row++) { FileIO::fread(bytedata, 1, pitch, f); bytedata += pitch; } } i++; } } return ret; }
bool write_dds_to_file(FILE *f, const dds_data &data) { if(!f) return false; uint32_t magic = dds_fourcc; DDS_HEADER header; DDS_HEADER_DXT10 headerDXT10; RDCEraseEl(header); RDCEraseEl(headerDXT10); header.dwSize = sizeof(DDS_HEADER); header.ddspf.dwSize = sizeof(DDS_PIXELFORMAT); header.dwWidth = data.width; header.dwHeight = data.height; header.dwDepth = data.depth; header.dwMipMapCount = data.mips; header.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT; if(data.mips > 1) header.dwFlags |= DDSD_MIPMAPCOUNT; if(data.depth > 1) header.dwFlags |= DDSD_DEPTH; bool blockFormat = false; if(data.format.Special()) { switch(data.format.type) { case ResourceFormatType::BC1: case ResourceFormatType::BC2: case ResourceFormatType::BC3: case ResourceFormatType::BC4: case ResourceFormatType::BC5: case ResourceFormatType::BC6: case ResourceFormatType::BC7: blockFormat = true; break; case ResourceFormatType::ETC2: case ResourceFormatType::EAC: case ResourceFormatType::ASTC: case ResourceFormatType::YUV: RDCERR("Unsupported file format, %u", data.format.type); return false; default: break; } } if(blockFormat) header.dwFlags |= DDSD_LINEARSIZE; else header.dwFlags |= DDSD_PITCH; header.dwCaps = DDSCAPS_TEXTURE; if(data.mips > 1) header.dwCaps |= DDSCAPS_MIPMAP; if(data.mips > 1 || data.slices > 1 || data.depth > 1) header.dwCaps |= DDSCAPS_COMPLEX; header.dwCaps2 = data.depth > 1 ? DDSCAPS2_VOLUME : 0; bool dx10Header = false; headerDXT10.dxgiFormat = ResourceFormat2DXGIFormat(data.format); headerDXT10.resourceDimension = data.depth > 1 ? D3D10_RESOURCE_DIMENSION_TEXTURE3D : D3D10_RESOURCE_DIMENSION_TEXTURE2D; headerDXT10.miscFlag = 0; headerDXT10.arraySize = data.slices; if(headerDXT10.dxgiFormat == DXGI_FORMAT_UNKNOWN) { RDCERR("Couldn't convert resource format to DXGI format"); return false; } if(data.cubemap) { header.dwCaps2 = DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES; headerDXT10.miscFlag |= DDS_RESOURCE_MISC_TEXTURECUBE; headerDXT10.arraySize /= 6; } if(headerDXT10.arraySize > 1) dx10Header = true; // need to specify dx10 header to give array size uint32_t bytesPerPixel = 1; if(blockFormat) { int blockSize = (data.format.type == ResourceFormatType::BC1 || data.format.type == ResourceFormatType::BC4) ? 8 : 16; header.dwPitchOrLinearSize = RDCMAX(1U, ((header.dwWidth + 3) / 4)) * blockSize; } else { switch(data.format.type) { case ResourceFormatType::S8: bytesPerPixel = 1; break; case ResourceFormatType::R10G10B10A2: case ResourceFormatType::R9G9B9E5: case ResourceFormatType::R11G11B10: case ResourceFormatType::D24S8: bytesPerPixel = 4; break; case ResourceFormatType::R5G6B5: case ResourceFormatType::R5G5B5A1: case ResourceFormatType::R4G4B4A4: bytesPerPixel = 2; break; case ResourceFormatType::D32S8: bytesPerPixel = 8; break; case ResourceFormatType::D16S8: case ResourceFormatType::YUV: case ResourceFormatType::R4G4: RDCERR("Unsupported file format %u", data.format.type); return false; default: bytesPerPixel = data.format.compCount * data.format.compByteWidth; } header.dwPitchOrLinearSize = header.dwWidth * bytesPerPixel; } // special case a couple of formats to write out non-DX10 style, for // backwards compatibility if(data.format.compByteWidth == 1 && data.format.compCount == 4 && data.format.compType == CompType::UNorm) { header.ddspf.dwFlags = DDPF_RGBA; header.ddspf.dwRGBBitCount = 32; header.ddspf.dwRBitMask = 0x000000ff; header.ddspf.dwGBitMask = 0x0000ff00; header.ddspf.dwBBitMask = 0x00ff0000; header.ddspf.dwABitMask = 0xff000000; if(data.format.bgraOrder) std::swap(header.ddspf.dwRBitMask, header.ddspf.dwBBitMask); } else if(data.format.type == ResourceFormatType::BC1) { header.ddspf.dwFlags = DDPF_FOURCC; header.ddspf.dwFourCC = MAKE_FOURCC('D', 'X', 'T', '1'); } else if(data.format.type == ResourceFormatType::BC2) { header.ddspf.dwFlags = DDPF_FOURCC; header.ddspf.dwFourCC = MAKE_FOURCC('D', 'X', 'T', '3'); } else if(data.format.type == ResourceFormatType::BC3) { header.ddspf.dwFlags = DDPF_FOURCC; header.ddspf.dwFourCC = MAKE_FOURCC('D', 'X', 'T', '5'); } else if(data.format.type == ResourceFormatType::BC4 && data.format.compType == CompType::UNorm) { header.ddspf.dwFlags = DDPF_FOURCC; header.ddspf.dwFourCC = MAKE_FOURCC('B', 'C', '4', 'U'); } else if(data.format.type == ResourceFormatType::BC4 && data.format.compType == CompType::SNorm) { header.ddspf.dwFlags = DDPF_FOURCC; header.ddspf.dwFourCC = MAKE_FOURCC('B', 'C', '4', 'S'); } else if(data.format.type == ResourceFormatType::BC5 && data.format.compType == CompType::UNorm) { header.ddspf.dwFlags = DDPF_FOURCC; header.ddspf.dwFourCC = MAKE_FOURCC('A', 'T', 'I', '2'); } else if(data.format.type == ResourceFormatType::BC5 && data.format.compType == CompType::SNorm) { header.ddspf.dwFlags = DDPF_FOURCC; header.ddspf.dwFourCC = MAKE_FOURCC('B', 'C', '5', 'S'); } else { // just write out DX10 header dx10Header = true; } if(dx10Header) { header.ddspf.dwFlags = DDPF_FOURCC; header.ddspf.dwFourCC = MAKE_FOURCC('D', 'X', '1', '0'); } { FileIO::fwrite(&magic, sizeof(magic), 1, f); FileIO::fwrite(&header, sizeof(header), 1, f); if(dx10Header) FileIO::fwrite(&headerDXT10, sizeof(headerDXT10), 1, f); int i = 0; for(int slice = 0; slice < RDCMAX(1, data.slices); slice++) { for(int mip = 0; mip < RDCMAX(1, data.mips); mip++) { int numdepths = RDCMAX(1, data.depth >> mip); for(int d = 0; d < numdepths; d++) { byte *bytedata = data.subdata[i]; int rowlen = RDCMAX(1, data.width >> mip); int numRows = RDCMAX(1, data.height >> mip); int pitch = RDCMAX(1U, rowlen * bytesPerPixel); // pitch/rows are in blocks, not pixels, for block formats. if(blockFormat) { numRows = RDCMAX(1, numRows / 4); int blockSize = (data.format.type == ResourceFormatType::BC1 || data.format.type == ResourceFormatType::BC4) ? 8 : 16; pitch = RDCMAX(blockSize, (((rowlen + 3) / 4)) * blockSize); } for(int row = 0; row < numRows; row++) { FileIO::fwrite(bytedata, 1, pitch, f); bytedata += pitch; } i++; } } } } return true; }
* all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. ******************************************************************************/ #include "dds_readwrite.h" #include <stdint.h> #include "common/common.h" static const uint32_t dds_fourcc = MAKE_FOURCC('D', 'D', 'S', ' '); // from MSDN struct DDS_PIXELFORMAT { uint32_t dwSize; uint32_t dwFlags; uint32_t dwFourCC; uint32_t dwRGBBitCount; uint32_t dwRBitMask; uint32_t dwGBitMask; uint32_t dwBBitMask; uint32_t dwABitMask; }; struct DDS_HEADER
int32 CMp4FileWriter::Stop() { ISO_MOVIE_BOX movie_box; ISO_MOVIE_HEADER_BOX movie_header_box; ISO_TRACK_BOX track_box; ISO_TRACK_HEADER_BOX track_header_box; ISO_MEDIA_BOX media_box; ISO_MEDIA_HEADER_BOX media_header_box; ISO_HANDLER_BOX handler_box; ISO_MEDIA_INFO_BOX media_info_box; ISO_VIDEO_MEDIA_HEADER_BOX video_media_header_box; ISO_SOUND_MEDIA_HEADER_BOX sound_media_header_box; ISO_DATA_INFO_BOX data_info_box; ISO_DATA_REF_BOX data_ref_box; ISO_DATA_ENTRY data_entry; ISO_SAMPLE_TABLE_BOX sample_table_box; ISO_VISUAL_SAMPLE_DESC_BOX visual_sample_desc_box; ISO_VISUAL_SAMPLE_ENTRY visual_sample_entry; ISO_AUDIO_SAMPLE_DESC_BOX audio_sample_desc_box; ISO_AUDIO_SAMPLE_ENTRY audio_sample_entry; ISO_TIME_TO_SAMPLE_BOX time_to_sample_box; ISO_TIME_TO_SAMPLE_ENTRY time_to_sample_entry; ISO_SAMPLE_SIZE_BOX sample_size_box; ISO_SAMPLE_TO_CHUNK_BOX sample_to_chunk_box; ISO_CHUNK_OFFSET_BOX chunk_offset_box; ISO_SYNC_SAMPLE_BOX sync_sample_box; ISO_SAMPLE_TO_CHUNK_ENTRY sample_to_chunk_entry; AVC_SAMPLE_DESC_BOX avc_sample_desc_box; AVC_SPS_RECORD avc_sps_record; AVC_PPS_RECORD avc_pps_record; AAC_SAMPLE_DESC_BOX aac_sample_desc_box; AAC_SAMPLE_ENTRY aac_sample_entry; uint32 movie_box_offset; uint32 track_box_offset; uint32 track_box_size; uint32 media_box_offset; uint32 media_box_size; uint32 media_info_box_offset; uint32 media_info_box_size; uint32 data_info_box_offset; uint32 data_info_box_size; uint32 sample_table_box_offset; uint32 sample_table_box_size; //uint32 sample_size_box_offset; //uint32 sample_size_box_size; int32 mux_size; uint32 total_mux_size; time_t utc_time; uint32 creation_time; uint32 modification_time; //uint32 time_scale; //uint32 duration; uint32 total_entry_size; int32 b_open; uint32 write_size; int8 str[MP4_FILE_WRITER_MAX_STR_SIZE + 1]; uint8 dec_spec_buf[MP4_FILE_WRITER_MAX_DEC_SPEC_BUF_SIZE]; int32 dec_spec_buf_size; uint8* p_uint8 = NULL; uint8* p_buf_offset = NULL; uint32* p_uint32 = NULL; int32 buf_left_size; int32 i; int32 ret; if( !m_bInit ) { return -1; } if( !m_bStart ) { return 0; } ret = gen_file_is_open(m_hFile, &b_open); if( !b_open ) { goto FIN; } p_uint8 = m_pWriteBuf; buf_left_size = m_WriteBufSize; /** movie box */ movie_box_offset = m_TotalWriteSize; total_mux_size = 0; movie_box.box.size = 0x0; mux_size = buf_left_size; ret = mp4_make_movie_box(m_Muxer, &movie_box, p_uint8, &mux_size); ret = gen_file_write(m_hFile, (int8*)p_uint8, mux_size, &write_size); m_TotalWriteSize += mux_size; total_mux_size += mux_size; /** movie header box */ utc_time = time(NULL); creation_time = utc_time + MP4_UTC_TIME_1904_TO_1970; modification_time = creation_time; movie_header_box.creation_time = creation_time; movie_header_box.modification_time = modification_time; if( m_bHasVideo ) { movie_header_box.time_scale = m_TimeScale; movie_header_box.duration = m_TotalVideoElapseTime; }else if( m_bHasAudio ) { movie_header_box.time_scale = m_TimeScale; movie_header_box.duration = m_TotalAudioElapseTime; }else { movie_header_box.time_scale = m_TimeScale; movie_header_box.duration = UINT32_MAX; } movie_header_box.next_track_id = MP4_FILE_WRITER_MAX_TRACK_ID + 1; mux_size = buf_left_size; ret = mp4_make_movie_header_box(m_Muxer, &movie_header_box, p_uint8, &mux_size); ret = gen_file_write(m_hFile, (int8*)p_uint8, mux_size, &write_size); m_TotalWriteSize += mux_size; total_mux_size += mux_size; memset(str, 0, MP4_FILE_WRITER_MAX_STR_SIZE + 1); str[0] = 0x0; /** track */ for( i = 0; i < m_TrackNum; i++ ) { /** track box */ track_box_offset = m_TotalWriteSize; track_box_size = 0; track_box.box.size = 0; mux_size = buf_left_size; ret = mp4_make_track_box(m_Muxer, &track_box, p_uint8, &mux_size); ret = gen_file_write(m_hFile, (int8*)p_uint8, mux_size, &write_size); m_TotalWriteSize += mux_size; track_box_size += mux_size; total_mux_size += mux_size; /** track header box */ track_header_box.full_box.version_flag.value = (MP4_FULL_BOX_VERSION_0 << MP4_FULL_BOX_VERSION_BIT_OFFSET) | (MP4_TRACK_ENABLE_FLAG | MP4_TRACK_IN_MOVIE_FLAG | MP4_TRACK_IN_PREVIEW_FLAG); track_header_box.creation_time = creation_time; track_header_box.modification_time = modification_time; if( m_Track[i] == MP4_TRACK_TYPE_VIDEO ) { track_header_box.track_id = MP4_FILE_WRITER_VIDEO_TRACK_ID; track_header_box.duration = m_TotalVideoElapseTime; track_header_box.volume = 0x0; }else { track_header_box.track_id = MP4_FILE_WRITER_AUDIO_TRACK_ID; track_header_box.duration = m_TotalAudioElapseTime; track_header_box.volume = 0x0100; } track_header_box.width = m_VideoFrame.param.video.width << 16; track_header_box.height = m_VideoFrame.param.video.height << 16; mux_size = buf_left_size; ret = mp4_make_track_header_box(m_Muxer, &track_header_box, p_uint8, &mux_size); ret = gen_file_write(m_hFile, (int8*)p_uint8, mux_size, &write_size); m_TotalWriteSize += mux_size; track_box_size += mux_size; total_mux_size += mux_size; /** media box */ media_box_offset = m_TotalWriteSize; media_box_size = 0; media_box.box.size = 0; mux_size = buf_left_size; ret = mp4_make_media_box(m_Muxer, &media_box, p_uint8, &mux_size); ret = gen_file_write(m_hFile, (int8*)p_uint8, mux_size, &write_size); m_TotalWriteSize += mux_size; media_box_size += mux_size; track_box_size += mux_size; total_mux_size += mux_size; /** media header box */ media_header_box.creation_time = creation_time; media_header_box.modification_time = modification_time; if( m_Track[i] == MP4_TRACK_TYPE_VIDEO ) { media_header_box.time_scale = m_TimeScale; media_header_box.duration = m_TotalVideoElapseTime; }else { //media_header_box.time_scale = m_AudioFrame.param.audio.sample_rate; media_header_box.time_scale = m_TimeScale; media_header_box.duration = m_TotalAudioElapseTime; } //chi media_header_box.language = 0x0D09; mux_size = buf_left_size; ret = mp4_make_media_header_box(m_Muxer, &media_header_box, p_uint8, &mux_size); ret = gen_file_write(m_hFile, (int8*)p_uint8, mux_size, &write_size); m_TotalWriteSize += mux_size; media_box_size += mux_size; track_box_size += mux_size; total_mux_size += mux_size; /** handler ref box */ if( m_Track[i] == MP4_TRACK_TYPE_VIDEO ) { handler_box.handler_type = MP4_HANDLER_TYPE_VIDE; }else { handler_box.handler_type = MP4_HANDLER_TYPE_SOUN; } handler_box.p_name = str; handler_box.name_size = 1; mux_size = buf_left_size; ret = mp4_make_handler_box(m_Muxer, &handler_box, p_uint8, &mux_size); ret = gen_file_write(m_hFile, (int8*)p_uint8, mux_size, &write_size); m_TotalWriteSize += mux_size; media_box_size += mux_size; track_box_size += mux_size; total_mux_size += mux_size; /** media info box */ media_info_box_offset = m_TotalWriteSize; media_info_box_size = 0; media_info_box.box.size = 0; mux_size = buf_left_size; ret = mp4_make_media_info_box(m_Muxer, &media_info_box, p_uint8, &mux_size); ret = gen_file_write(m_hFile, (int8*)p_uint8, mux_size, &write_size); m_TotalWriteSize += mux_size; media_info_box_size += mux_size; media_box_size += mux_size; track_box_size += mux_size; total_mux_size += mux_size; if( m_Track[i] == MP4_TRACK_TYPE_VIDEO ) { /** video media header box */ mux_size = buf_left_size; ret = mp4_make_video_media_header_box(m_Muxer, &video_media_header_box, p_uint8, &mux_size); ret = gen_file_write(m_hFile, (int8*)p_uint8, mux_size, &write_size); m_TotalWriteSize += mux_size; media_info_box_size += mux_size; media_box_size += mux_size; track_box_size += mux_size; total_mux_size += mux_size; }else { /** sound media header box */ mux_size = buf_left_size; ret = mp4_make_sound_media_header_box(m_Muxer, &sound_media_header_box, p_uint8, &mux_size); ret = gen_file_write(m_hFile, (int8*)p_uint8, mux_size, &write_size); m_TotalWriteSize += mux_size; media_info_box_size += mux_size; media_box_size += mux_size; track_box_size += mux_size; total_mux_size += mux_size; } /** data info box */ data_info_box_offset = m_TotalWriteSize; data_info_box_size = 0; mux_size = buf_left_size; ret = mp4_make_data_info_box(m_Muxer, &data_info_box, p_uint8, &mux_size); ret = gen_file_write(m_hFile, (int8*)p_uint8, mux_size, &write_size); m_TotalWriteSize += mux_size; data_info_box_size += mux_size; media_info_box_size += mux_size; media_box_size += mux_size; track_box_size += mux_size; total_mux_size += mux_size; /** data ref box */ data_entry.entry_type = MP4_DATA_ENTRY_TYPE_URL; data_entry.entry_box.url.full_box.version_flag.value = (MP4_FULL_BOX_VERSION_0 << MP4_FULL_BOX_VERSION_BIT_OFFSET) | MP4_DATA_ENTRY_FLAG_SELF_CONTAIN; data_entry.entry_box.url.p_location = NULL; data_entry.entry_box.url.location_size = 0; data_ref_box.entry_count = 1; data_ref_box.p_entry = &data_entry; mux_size = buf_left_size; ret = mp4_make_data_ref_box(m_Muxer, &data_ref_box, p_uint8, &mux_size); ret = gen_file_write(m_hFile, (int8*)p_uint8, mux_size, &write_size); m_TotalWriteSize += mux_size; data_info_box_size += mux_size; media_info_box_size += mux_size; media_box_size += mux_size; track_box_size += mux_size; total_mux_size += mux_size; /** rewrite data info box size */ ret = gen_file_seek(m_hFile, GEN_FILE_SEEK_BEGIN, data_info_box_offset, NULL); data_info_box_size = hton_u32(data_info_box_size); ret = gen_file_write(m_hFile, (int8*)&data_info_box_size, sizeof(data_info_box_size), &write_size); ret = gen_file_seek(m_hFile, GEN_FILE_SEEK_END, 0, NULL); /** sample table box */ sample_table_box_offset = m_TotalWriteSize; sample_table_box_size = 0; mux_size = buf_left_size; ret = mp4_make_sample_table_box(m_Muxer, &sample_table_box, p_uint8, &mux_size); ret = gen_file_write(m_hFile, (int8*)p_uint8, mux_size, &write_size); m_TotalWriteSize += mux_size; sample_table_box_size += mux_size; media_info_box_size += mux_size; media_box_size += mux_size; track_box_size += mux_size; total_mux_size += mux_size; /** sample desc box */ if( m_Track[i] == MP4_TRACK_TYPE_VIDEO ) { /** visual */ if( m_VideoFourcc == MAKE_FOURCC('a','v','c','1') ) { avc_sample_desc_box.entry.visual.entry.data_ref_index = 0x1; avc_sample_desc_box.entry.visual.width = m_VideoFrame.param.video.width; avc_sample_desc_box.entry.visual.height = m_VideoFrame.param.video.height; memset(avc_sample_desc_box.entry.visual.compressor_name, 0, ISO_MEDIA_FILE_COMPRESSOR_NAME_SIZE); avc_sample_desc_box.entry.config.record.profile = m_Profile; avc_sample_desc_box.entry.config.record.profile_compat = m_ProfileCompat; avc_sample_desc_box.entry.config.record.level = m_Level; avc_sample_desc_box.entry.config.record.len_size_minus_1 = 0x3; if( m_bGetSps ) { avc_sps_record.nalu_len = m_SPSNaluSize; avc_sps_record.p_nalu = m_pSPSBuf; avc_sample_desc_box.entry.config.record.sps_count = 1; avc_sample_desc_box.entry.config.record.p_sps = &avc_sps_record; }else { avc_sample_desc_box.entry.config.record.sps_count = 0; avc_sample_desc_box.entry.config.record.p_sps = NULL; } if( m_bGetPps ) { avc_pps_record.nalu_len = m_PPSNaluSize; avc_pps_record.p_nalu = m_pPPSBuf; avc_sample_desc_box.entry.config.record.pps_count = 1; avc_sample_desc_box.entry.config.record.p_pps = &avc_pps_record; }else { avc_sample_desc_box.entry.config.record.pps_count = 0; avc_sample_desc_box.entry.config.record.p_pps = NULL; } mux_size = buf_left_size; ret = mp4_make_avc_sample_desc_box(m_Muxer, &avc_sample_desc_box, p_uint8, &mux_size); }else { visual_sample_entry.entry.box.type = m_VideoFourcc; visual_sample_entry.entry.data_ref_index = 0x1; visual_sample_entry.width = m_VideoFrame.param.video.width; visual_sample_entry.height = m_VideoFrame.param.video.height; memset(visual_sample_entry.compressor_name, 0, ISO_MEDIA_FILE_COMPRESSOR_NAME_SIZE); visual_sample_desc_box.entry_count = 1; visual_sample_desc_box.p_entry = &visual_sample_entry; mux_size = buf_left_size; ret = mp4_make_visual_sample_desc_box(m_Muxer, &visual_sample_desc_box, p_uint8, &mux_size); } ret = gen_file_write(m_hFile, (int8*)p_uint8, mux_size, &write_size); m_TotalWriteSize += mux_size; sample_table_box_size += mux_size; media_info_box_size += mux_size; media_box_size += mux_size; track_box_size += mux_size; total_mux_size += mux_size; }else { /** audio */ //if( m_AudioFourcc == MAKE_FOURCC('m','p','4','a') ) if( m_AudioFrame.param.audio.algo == MP_AUDIO_AAC_LC ) { aac_sample_entry.audio.entry.data_ref_index = 0x1; aac_sample_entry.audio.sample_rate = m_AudioFrame.param.audio.sample_rate << 16; aac_sample_entry.es_box.es_desc.base.size.bit_size = MPEG4_SIZE_ENCODING_8_BIT; aac_sample_entry.es_box.es_desc.es_id = MP4_FILE_WRITER_AUDIO_TRACK_ID; aac_sample_entry.es_box.es_desc.stream_depend_flag = 0x0; aac_sample_entry.es_box.es_desc.url_flag = 0x0; aac_sample_entry.es_box.es_desc.ocr_stream_flag = 0x0; aac_sample_entry.es_box.es_desc.stream_priority = 0x0; aac_sample_entry.es_box.es_desc.dec_config.base.size.bit_size = MPEG4_SIZE_ENCODING_8_BIT; aac_sample_entry.es_box.es_desc.dec_config.obj_type = MPEG4_OBJECT_TYPE_AUDIO_MPEG4; aac_sample_entry.es_box.es_desc.dec_config.stream_type = MPEG4_STREAM_TYPE_AUDIO_STREAM; aac_sample_entry.es_box.es_desc.dec_config.buf_size = 15000; aac_sample_entry.es_box.es_desc.dec_config.max_bitrate = 1500 * 1000; aac_sample_entry.es_box.es_desc.dec_config.avg_bitrate = 0; dec_spec_buf[0] = MPEG4_DEC_SPEC_INFO_TAG; dec_spec_buf_size = MP4_FILE_WRITER_MAX_DEC_SPEC_BUF_SIZE; ret = MakeAudioDecSpecInfo(dec_spec_buf + 2, &dec_spec_buf_size); dec_spec_buf[1] = dec_spec_buf_size; aac_sample_entry.es_box.es_desc.dec_config.p_vdec_spec_info = dec_spec_buf; aac_sample_entry.es_box.es_desc.dec_config.vdec_spec_info_size = dec_spec_buf_size + 2; aac_sample_entry.es_box.es_desc.sl_config.base.size.bit_size = MPEG4_SIZE_ENCODING_8_BIT; aac_sample_entry.es_box.es_desc.sl_config.predefine = MPEG4_PREDEFINE_MP4; aac_sample_desc_box.entry_count = 1; aac_sample_desc_box.p_entry = &aac_sample_entry; mux_size = buf_left_size; ret = mp4_make_aac_sample_desc_box(m_Muxer, &aac_sample_desc_box, p_uint8, &mux_size); }else { audio_sample_entry.entry.box.type = m_AudioFourcc; audio_sample_entry.entry.data_ref_index = 0x1; audio_sample_entry.chn_count = m_AudioFrame.param.audio.chn; audio_sample_entry.sample_rate = m_AudioFrame.param.audio.sample_rate << 16; audio_sample_desc_box.entry_count = 1; audio_sample_desc_box.p_entry = &audio_sample_entry; mux_size = buf_left_size; ret = mp4_make_audio_sample_desc_box(m_Muxer, &audio_sample_desc_box, p_uint8, &mux_size); } ret = gen_file_write(m_hFile, (int8*)p_uint8, mux_size, &write_size); m_TotalWriteSize += mux_size; sample_table_box_size += mux_size; media_info_box_size += mux_size; media_box_size += mux_size; track_box_size += mux_size; total_mux_size += mux_size; } /** time to sample box */ if( m_Track[i] == MP4_TRACK_TYPE_VIDEO ) { total_entry_size = MP4_TIME_TO_SAMPLE_ENTRY_SIZE * m_VideoFrameCount; time_to_sample_box.entry_count = m_VideoFrameCount; time_to_sample_box.p_entry = m_pVideoTimeEntry; if( m_VideoFrameCount == 1 ) { m_pVideoTimeEntry[m_VideoFrameCount - 1].sample_delta = hton_u32(40); }else { m_pVideoTimeEntry[m_VideoFrameCount - 1].sample_delta = m_pVideoTimeEntry[m_VideoFrameCount - 2].sample_delta; } }else { total_entry_size = MP4_TIME_TO_SAMPLE_ENTRY_SIZE * m_AudioFrameCount; time_to_sample_box.entry_count = m_AudioFrameCount; time_to_sample_box.p_entry = m_pAudioTimeEntry; if( m_AudioFrameCount == 1 ) { m_pAudioTimeEntry[m_AudioFrameCount - 1].sample_delta = hton_u32(48000 / 1024); }else { m_pAudioTimeEntry[m_AudioFrameCount - 1].sample_delta = m_pAudioTimeEntry[m_AudioFrameCount - 2].sample_delta; } } mux_size = buf_left_size; ret = mp4_make_time_to_sample_box(m_Muxer, &time_to_sample_box, p_uint8, &mux_size); ret = gen_file_write(m_hFile, (int8*)p_uint8, mux_size, &write_size); m_TotalWriteSize += mux_size; sample_table_box_size += mux_size; media_info_box_size += mux_size; media_box_size += mux_size; track_box_size += mux_size; total_mux_size += mux_size; //total_entry_size = MP4_TIME_TO_SAMPLE_ENTRY_SIZE; //ret = gen_file_write(m_hFile, (int8*)&time_to_sample_entry, total_entry_size, &write_size); if( m_Track[i] == MP4_TRACK_TYPE_VIDEO ) { ret = gen_file_write(m_hFile, (int8*)m_pVideoTimeEntry, total_entry_size, &write_size); }else { ret = gen_file_write(m_hFile, (int8*)m_pAudioTimeEntry, total_entry_size, &write_size); } m_TotalWriteSize += total_entry_size; sample_table_box_size += total_entry_size; media_info_box_size += total_entry_size; media_box_size += total_entry_size; track_box_size += total_entry_size; total_mux_size += total_entry_size; /** sample size box */ if( m_Track[i] == MP4_TRACK_TYPE_VIDEO ) { total_entry_size = MP4_SAMPLE_SIZE_ENTRY_SIZE * m_VideoFrameCount; sample_size_box.sample_count = m_VideoFrameCount; }else { total_entry_size = MP4_SAMPLE_SIZE_ENTRY_SIZE * m_AudioFrameCount; sample_size_box.sample_count = m_AudioFrameCount; } sample_size_box.full_box.box.size = MP4_SAMPLE_SIZE_BOX_MIN_SIZE + total_entry_size; sample_size_box.sample_size = 0x0; mux_size = buf_left_size; ret = mp4_make_sample_size_box(m_Muxer, &sample_size_box, p_uint8, &mux_size); ret = gen_file_write(m_hFile, (int8*)p_uint8, mux_size, &write_size); m_TotalWriteSize += mux_size; sample_table_box_size += mux_size; media_info_box_size += mux_size; media_box_size += mux_size; track_box_size += mux_size; total_mux_size += mux_size; if( m_Track[i] == MP4_TRACK_TYPE_VIDEO ) { ret = gen_file_write(m_hFile, (int8*)m_pVideoSizeEntry, total_entry_size, &write_size); }else { ret = gen_file_write(m_hFile, (int8*)m_pAudioSizeEntry, total_entry_size, &write_size); } m_TotalWriteSize += total_entry_size; sample_table_box_size += total_entry_size; media_info_box_size += total_entry_size; media_box_size += total_entry_size; track_box_size += total_entry_size; total_mux_size += total_entry_size; /** sample to chunk box */ sample_to_chunk_entry.first_chunk = hton_u32(0x1); sample_to_chunk_entry.sample_per_chunk = hton_u32(0x1); sample_to_chunk_entry.sample_desc_index = hton_u32(0x1); sample_to_chunk_box.entry_count = 1; sample_to_chunk_box.p_entry = &sample_to_chunk_entry; mux_size = buf_left_size; ret = mp4_make_sample_to_chunk_box(m_Muxer, &sample_to_chunk_box, p_uint8, &mux_size); ret = gen_file_write(m_hFile, (int8*)p_uint8, mux_size, &write_size); m_TotalWriteSize += mux_size; sample_table_box_size += mux_size; media_info_box_size += mux_size; media_box_size += mux_size; track_box_size += mux_size; total_mux_size += mux_size; total_entry_size = MP4_SAMPLE_TO_CHUNK_ENTRY_SIZE; ret = gen_file_write(m_hFile, (int8*)&sample_to_chunk_entry, total_entry_size, &write_size); m_TotalWriteSize += total_entry_size; sample_table_box_size += total_entry_size; media_info_box_size += total_entry_size; media_box_size += total_entry_size; track_box_size += total_entry_size; total_mux_size += total_entry_size; /** chunk offset box */ if( m_Track[i] == MP4_TRACK_TYPE_VIDEO ) { total_entry_size = MP4_CHUNK_OFFSET_ENTRY_SIZE * m_VideoFrameCount; chunk_offset_box.entry_count = m_VideoFrameCount; }else { total_entry_size = MP4_CHUNK_OFFSET_ENTRY_SIZE * m_AudioFrameCount; chunk_offset_box.entry_count = m_AudioFrameCount; } chunk_offset_box.full_box.box.size = MP4_CHUNK_OFFSET_BOX_MIN_SIZE + total_entry_size; mux_size = buf_left_size; ret = mp4_make_chunk_offset_box(m_Muxer, &chunk_offset_box, p_uint8, &mux_size); ret = gen_file_write(m_hFile, (int8*)p_uint8, mux_size, &write_size); m_TotalWriteSize += mux_size; sample_table_box_size += mux_size; media_info_box_size += mux_size; media_box_size += mux_size; track_box_size += mux_size; total_mux_size += mux_size; if( m_Track[i] == MP4_TRACK_TYPE_VIDEO ) { ret = gen_file_write(m_hFile, (int8*)m_pVideoOffsetEntry, total_entry_size, &write_size); }else { ret = gen_file_write(m_hFile, (int8*)m_pAudioOffsetEntry, total_entry_size, &write_size); } m_TotalWriteSize += total_entry_size; sample_table_box_size += total_entry_size; media_info_box_size += total_entry_size; media_box_size += total_entry_size; track_box_size += total_entry_size; total_mux_size += total_entry_size; /** sync sample box */ if( m_Track[i] == MP4_TRACK_TYPE_VIDEO ) { total_entry_size = MP4_SYNC_SAMPLE_ENTRY_SIZE * m_VideoSyncEntryCount; sync_sample_box.entry_count = m_VideoSyncEntryCount; sync_sample_box.full_box.box.size = MP4_SYNC_SAMPLE_BOX_MIN_SIZE + total_entry_size; mux_size = buf_left_size; ret = mp4_make_sync_sample_box(m_Muxer, &sync_sample_box, p_uint8, &mux_size); ret = gen_file_write(m_hFile, (int8*)p_uint8, mux_size, &write_size); m_TotalWriteSize += mux_size; sample_table_box_size += mux_size; media_info_box_size += mux_size; media_box_size += mux_size; track_box_size += mux_size; total_mux_size += mux_size; ret = gen_file_write(m_hFile, (int8*)m_pVideoSyncEntry, total_entry_size, &write_size); m_TotalWriteSize += total_entry_size; sample_table_box_size += total_entry_size; media_info_box_size += total_entry_size; media_box_size += total_entry_size; track_box_size += total_entry_size; total_mux_size += total_entry_size; } /** rewrite sample table box size */ ret = gen_file_seek(m_hFile, GEN_FILE_SEEK_BEGIN, sample_table_box_offset, NULL); sample_table_box_size = hton_u32(sample_table_box_size); ret = gen_file_write(m_hFile, (int8*)&sample_table_box_size, sizeof(sample_table_box_size), &write_size); /** rewrite media info box size */ ret = gen_file_seek(m_hFile, GEN_FILE_SEEK_BEGIN, media_info_box_offset, NULL); media_info_box_size = hton_u32(media_info_box_size); ret = gen_file_write(m_hFile, (int8*)&media_info_box_size, sizeof(media_info_box_size), &write_size); /** rewrite media box size */ //file_pos.QuadPart = media_box_offset; //ret = SetFilePointerEx(m_hFile, file_pos, NULL, FILE_BEGIN); ret = gen_file_seek(m_hFile, GEN_FILE_SEEK_BEGIN, media_box_offset, NULL); media_box_size = hton_u32(media_box_size); ret = gen_file_write(m_hFile, (int8*)&media_box_size, sizeof(media_box_size), &write_size); /** rewrite track box size */ //file_pos.QuadPart = track_box_offset; //ret = SetFilePointerEx(m_hFile, file_pos, NULL, FILE_BEGIN); ret = gen_file_seek(m_hFile, GEN_FILE_SEEK_BEGIN, track_box_offset, NULL); track_box_size = hton_u32(track_box_size); ret = gen_file_write(m_hFile, (int8*)&track_box_size, sizeof(track_box_size), &write_size); //file_pos.QuadPart = 0; //ret = SetFilePointerEx(m_hFile, file_pos, NULL, FILE_END); ret = gen_file_seek(m_hFile, GEN_FILE_SEEK_END, 0, NULL); } /** rewrite movie box size */ //file_pos.QuadPart = movie_box_offset; //ret = SetFilePointerEx(m_hFile, file_pos, NULL, FILE_BEGIN); ret = gen_file_seek(m_hFile, GEN_FILE_SEEK_BEGIN, movie_box_offset, NULL); total_mux_size = hton_u32(total_mux_size); ret = gen_file_write(m_hFile, (int8*)&total_mux_size, sizeof(total_mux_size), &write_size); log_debug(_T("[CMp4FileWriter::Stop] total write %u bytes\n"), m_TotalWriteSize); gen_file_close(m_hFile); FIN: m_bStart = 0; return 0; }
#include "Endian.h" #include "Font.h" namespace WiiBanner { struct CharWidths { s8 left; // left space width of character u8 glyph_width; // glyph width of character s8 char_width; // character width = left space width + glyph width + right space width }; enum BinaryMagic : u32 { BINARY_MAGIC_FONT = MAKE_FOURCC('R', 'F', 'N', 'A'), BINARY_MAGIC_GLYPH_GROUP = MAKE_FOURCC('G', 'L', 'G', 'R'), BINARY_MAGIC_FONT_INFORMATION = MAKE_FOURCC('F', 'I', 'N', 'F'), BINARY_MAGIC_TEXTURE_GLYPH = MAKE_FOURCC('T', 'G', 'L', 'P'), BINARY_MAGIC_CHARACTER_CODE_MAP = MAKE_FOURCC('C', 'M', 'A', 'P'), BINARY_MAGIC_CHARACTER_WIDTH = MAKE_FOURCC('C', 'W', 'D', 'H') }; void Font::Load(std::istream& file) { const std::streamoff file_start = file.tellg(); // Read header FourCC header_magic; u16 endian;
int32 CMp4FileWriter::InputFrame(MEDIA_FRAME *p_frame) { uint32 uint32_data; uint32 write_size; H264_NALU_PACK nalu_pack; uint8* p_uint8 = NULL; int32 parse_size; int32 total_parse_size; int32 left_size; int32 nalu_size; int32 ret; if( p_frame == NULL ) { return -1; } if( !m_bInit ) { return -1; } if( !m_bStart ) { return -1; } if( !m_bFindKeyFrame ) { if( p_frame->type == MP_DATA_TYPE_VIDEO && p_frame->param.video.frame_type == MP_VIDEO_I_FRAME ) { m_bFindKeyFrame = 1; }else { return 0; } } switch( p_frame->type ) { case MP_DATA_TYPE_VIDEO: { if( !m_bEnableVideo ) { return 0; } if( !m_bHasVideo ) { m_bHasVideo = 1; m_Track[m_TrackNum] = MP4_TRACK_TYPE_VIDEO; m_TrackNum++; memcpy(&m_VideoFrame, p_frame, sizeof(MEDIA_FRAME)); switch( m_VideoFrame.param.video.algo ) { case MP_VIDEO_MPEG2: { //m_VideoFourcc = MAKE_FOURCC('m','p','g','v'); m_VideoFourcc = MAKE_FOURCC('M','P','E','G'); } break; case MP_VIDEO_MPEG4: { //m_VideoFourcc = MAKE_FOURCC('m','p','4','v'); m_VideoFourcc = MAKE_FOURCC('X','V','I','D'); } break; case MP_VIDEO_AVC: { m_VideoFourcc = MAKE_FOURCC('a','v','c','1'); h264_nalu_pack_init(&nalu_pack); p_uint8 = (uint8*)p_frame->p_frame; total_parse_size = 0; left_size = p_frame->frame_size; //m_bGetSps = 0; //m_bGetPps = 0; while( 1 ) { ret = h264_parse_nalu(&nalu_pack, p_uint8, left_size, &parse_size); p_uint8 += parse_size; total_parse_size += parse_size; left_size -= parse_size; if( ret ) { break; } nalu_size = parse_size - H264_BS_HEADER_SIZE; if( nalu_pack.nalu_type == H264_NALU_SPS ) { if( nalu_size <= H264_MAX_SPS_NALU_SIZE ) { if( !m_bGetSps ) { m_bGetSps = 1; m_Profile = nalu_pack.sps.profile; m_ProfileCompat = 0xD0; m_Level = nalu_pack.sps.level; memcpy(m_pSPSBuf, nalu_pack.p_start + H264_BS_HEADER_SIZE, nalu_size); m_SPSNaluSize = nalu_size; } } }else if( nalu_pack.nalu_type == H264_NALU_PPS ) { if( nalu_size <= H264_MAX_PPS_NALU_SIZE ) { if( !m_bGetPps ) { m_bGetPps = 1; memcpy(m_pPPSBuf, nalu_pack.p_start + H264_BS_HEADER_SIZE, nalu_size); m_PPSNaluSize = nalu_size; } } } } } break; case MP_VIDEO_H264: { m_VideoFourcc = MAKE_FOURCC('h','2','6','4'); } break; default: { m_VideoFourcc = MAKE_FOURCC('m','p','g','v'); } break; } } if( m_VideoFrameCount < MP4_FILE_WRITER_MAX_VIDEO_INDEX ) { m_pVideoTimeEntry[m_VideoFrameCount].sample_count = hton_u32(0x1); if( m_VideoFrameCount > 0 ) { uint32_data = p_frame->frame_ts - m_TotalVideoElapseTime; m_pVideoTimeEntry[m_VideoFrameCount - 1].sample_delta = hton_u32(uint32_data); } m_pVideoSizeEntry[m_VideoFrameCount].entry_size = hton_u32(p_frame->frame_size); m_pVideoOffsetEntry[m_VideoFrameCount].chunk_offset = hton_u32(m_TotalWriteSize); if( p_frame->param.video.frame_type == MP_VIDEO_I_FRAME && m_VideoSyncEntryCount < MP4_FILE_WRITER_MAX_VIDEO_SYNC_ENTRY_NUM ) { m_pVideoSyncEntry[m_VideoSyncEntryCount].sample_number = hton_u32(m_VideoFrameCount + 1); m_VideoSyncEntryCount++; } } m_VideoFrameCount++; m_TotalVideoElapseTime = p_frame->frame_ts; m_TotalVideoFrameSize += p_frame->frame_size; } break; case MP_DATA_TYPE_AUDIO: { if( !m_bEnableAudio ) { return 0; } if( !m_bHasAudio ) { m_bHasAudio = 1; m_Track[m_TrackNum] = MP4_TRACK_TYPE_AUDIO; m_TrackNum++; memcpy(&m_AudioFrame, p_frame, sizeof(MEDIA_FRAME)); switch( m_AudioFrame.param.audio.algo ) { case MP_AUDIO_PCM: { m_AudioFourcc = MAKE_FOURCC('l','p','c','m'); m_AudioSamplePerFrame = 1024; } break; case MP_AUDIO_ADPCM: { m_AudioFourcc = MAKE_FOURCC('a','p','c','m'); m_AudioSamplePerFrame = 1024; } break; case MP_AUDIO_G711A: { m_AudioFourcc = MAKE_FOURCC('a','l','a','w'); //m_AudioFourcc = MAKE_FOURCC(0x06,0x00,0x00,0x00); m_AudioSamplePerFrame = 240; } break; case MP_AUDIO_G711U: { m_AudioFourcc = MAKE_FOURCC('u','l','a','w'); m_AudioSamplePerFrame = 240; } break; case MP_AUDIO_MP1: case MP_AUDIO_MP2: case MP_AUDIO_MP3: { //m_AudioFourcc = MAKE_FOURCC(0x50,0x00,0x00,0x00); m_AudioFourcc = MAKE_FOURCC('m','p','g','a'); m_AudioSamplePerFrame = 1152; } break; case MP_AUDIO_AAC: case MP_AUDIO_AAC_LC: { m_AudioFourcc = MAKE_FOURCC('m','p','4','a'); m_AudioSamplePerFrame = 1024 * m_TimeScale / m_AudioFrame.param.audio.sample_rate; //m_AudioSamplePerFrame = 1024; } break; default: { m_AudioFourcc = MAKE_FOURCC('m','p','g','a'); m_AudioSamplePerFrame = 1024; } break; } } if( m_AudioFrameCount < MP4_FILE_WRITER_MAX_AUDIO_INDEX ) { m_pAudioTimeEntry[m_AudioFrameCount].sample_count = hton_u32(0x1); if( m_AudioFrameCount > 0 ) { uint32_data = p_frame->frame_ts - m_TotalAudioElapseTime; m_pAudioTimeEntry[m_AudioFrameCount - 1].sample_delta = hton_u32(uint32_data); } m_pAudioSizeEntry[m_AudioFrameCount].entry_size = hton_u32(p_frame->frame_size); m_pAudioOffsetEntry[m_AudioFrameCount].chunk_offset = hton_u32(m_TotalWriteSize); } m_AudioFrameCount++; //m_TotalAudioElapseTime += m_AudioSamplePerFrame; m_TotalAudioElapseTime = p_frame->frame_ts; m_TotalAudioFrameSize += p_frame->frame_size; } break; default: { return -3; } } /** rewrite media data box size */ m_TotalFrameSize += p_frame->frame_size; ret = gen_file_seek(m_hFile, GEN_FILE_SEEK_BEGIN, m_MediaDataOffset, NULL); uint32_data = m_TotalFrameSize + m_MediaDataBoxSize; uint32_data = hton_u32(uint32_data); ret = gen_file_write(m_hFile, (int8*)&uint32_data, sizeof(uint32_data), &write_size); ret = gen_file_seek(m_hFile, GEN_FILE_SEEK_END, 0, NULL); /** write frame */ ret = gen_file_write(m_hFile, p_frame->p_frame, p_frame->frame_size, &write_size); m_TotalWriteSize += p_frame->frame_size; return 0; }
/*********************************************************** * Name: vchi_bulk_aux_service_init * * Arguments: VCHI_CONNECTION_T *connections, * const uint32_t num_connections * * Description: Routine to init the bulk auxiliary service * * Returns: int32_t - success == 0 * ***********************************************************/ int32_t vchi_bulk_aux_service_init( VCHI_CONNECTION_T **connections, const uint32_t num_connections, void **state ) { int32_t success = 0; uint32_t count = 0; BULK_AUX_SERVICE_INFO_T *bulk_aux_info = (BULK_AUX_SERVICE_INFO_T *)*state; os_assert(num_connections <= VCHI_MAX_NUM_CONNECTIONS); if (!bulk_aux_info) { bulk_aux_info = (BULK_AUX_SERVICE_INFO_T *)os_malloc( VCHI_MAX_NUM_CONNECTIONS * sizeof(BULK_AUX_SERVICE_INFO_T), 0, "vchi:bulk_aux_info" ); memset( bulk_aux_info, 0,VCHI_MAX_NUM_CONNECTIONS * sizeof(BULK_AUX_SERVICE_INFO_T) ); for( count = 0; count < num_connections; count++ ) { // record the connection info bulk_aux_info[count].connection = connections[count]; // create the server (this is a misnomer as the the BULX service acts as both client and server success += (connections[count])->api->service_connect((connections[count])->state,MAKE_FOURCC("BULX"),0,0,VC_TRUE,bulk_aux_callback,&bulk_aux_info[count],VC_FALSE,VC_FALSE,VC_FALSE,&bulk_aux_info[count].open_handle); os_assert(success == 0); } } else { for( count = 0; count < num_connections; count++ ) { os_assert( bulk_aux_info[count].connection == connections[count]); } } *state = bulk_aux_info; return success; }
static void gst_tiswhitebalance_fixate_caps (GstBaseTransform* base, GstPadDirection direction, GstCaps* incoming, GstCaps* outgoing) { GstTisWhiteBalance* self = GST_TISWHITEBALANCE(base); GstStructure* ins; GstStructure* outs; gint width, height; g_return_if_fail (gst_caps_is_fixed (incoming)); GST_DEBUG_OBJECT (base, "trying to fixate outgoing caps %" GST_PTR_FORMAT " based on caps %" GST_PTR_FORMAT, outgoing, incoming); ins = gst_caps_get_structure (incoming, 0); outs = gst_caps_get_structure (outgoing, 0); if (gst_structure_get_int (ins, "width", &width)) { if (gst_structure_has_field (outs, "width")) { gst_structure_fixate_field_nearest_int (outs, "width", width); } self->width = width; } if (gst_structure_get_int (ins, "height", &height)) { if (gst_structure_has_field (outs, "height")) { gst_structure_fixate_field_nearest_int (outs, "height", height); } self->height = height; } const char* p = gst_structure_get_name (ins); guint fourcc; if (g_strcmp0(p, "video/x-raw-bayer") == 0) { if (gst_structure_get_field_type (ins, "format") == G_TYPE_STRING) { const char *string; string = gst_structure_get_string (ins, "format"); fourcc = GST_STR_FOURCC (string); } else if (gst_structure_get_field_type (ins, "format") == GST_TYPE_FOURCC) { gst_structure_get_fourcc (ins, "format", &fourcc); } else fourcc = 0; if (fourcc == 0) { gst_debug_log (gst_tiswhitebalance_debug_category, GST_LEVEL_ERROR, "gst_tiswhitebalance", "gst_tiswhitebalance_fixate_caps", 0, NULL, "Unable to determine video format."); return; } if (fourcc == MAKE_FOURCC ('g','r','b','g')) { self->pattern = GR; } else if (fourcc == MAKE_FOURCC ('r', 'g', 'g', 'b')) { self->pattern = RG; } else if (fourcc == MAKE_FOURCC ('g', 'b', 'r', 'g')) { self->pattern = GB; } else if (fourcc == MAKE_FOURCC ('b', 'g', 'g', 'r')) { self->pattern = BG; } else { gst_debug_log (gst_tiswhitebalance_debug_category, GST_LEVEL_ERROR, "gst_tiswhitebalance", "gst_tiswhitebalance_fixate_caps", 0, NULL, "Unable to determine bayer pattern."); return; } gst_debug_log (gst_tiswhitebalance_debug_category, GST_LEVEL_INFO, "gst_tiswhitebalance", "gst_tiswhitebalance_fixate_caps", 0, NULL, "Using bayer format %s for whitebalancing.", bayer_to_string(self->pattern)); } else { gst_debug_log (gst_tiswhitebalance_debug_category, GST_LEVEL_INFO, "gst_tiswhitebalance", "gst_tiswhitebalance_fixate_caps", 0, NULL, "Not a bayer format. White balance will be disabled."); } }
int mphi_dumpmsg(mphi_driver_t* drv, const char* prefix, mphi_slot_t* slotptr) { const uint32_t ctrlid = MAKE_FOURCC("LRTC"); uint8_t* addr = (uint8_t*)slotptr->addr; uint32_t cmd, paylen, i; static int cnt = 0; char str[0x100]; int len; if(slotptr->ctrl && gVcDebug_SID != 0) // if(gVcDebug_SID != 0) { if(*(uint32_t*) (addr + 4) != gVcDebug_SID) { return 0; } } ++cnt; len = 0; len += sprintf(str + len, "[%04d %08u] %s %c tlen=%u ", cnt, timer_get_tick_count(), prefix, slotptr->ctrl ? 'c' : 'd', slotptr->len); if(slotptr->ctrl) { paylen = *(uint16_t*)(addr + 0xE); len += sprintf(str + len, "sid=%c%c%c%c slotcnt=0x%04X paylen=0x%04X ", addr[4], addr[5], addr[6], addr[7], *(uint16_t*)(addr + 0xC), paylen); if(*(uint32_t*)(addr + 4) == ctrlid && paylen > 0) { addr += 0x10; cmd = *(uint32_t*)(addr); switch(cmd) { case BULK_TRANSFER_RX: { len += sprintf(str + len, "cmd=%s(%d) sid=%c%c%c%c(%02X%02X%02X%02X) sz=0x%08X", mphi_ctrlcmd2str(cmd), cmd, addr[4], addr[5], addr[6], addr[7], addr[4], addr[5], addr[6], addr[7], *(uint32_t*)(addr + 0x8)); break; } case XON: case XOFF: { len += sprintf(str + len, "cmd=%s(%d) sid=%c%c%c%c", mphi_ctrlcmd2str(cmd), cmd, addr[4], addr[5], addr[6], addr[7] ); break; } default: { len += sprintf(str + len, "cmd=%s(%d) 0x%08X 0x%08X 0x%08X", mphi_ctrlcmd2str(cmd), cmd, *(uint32_t*)(addr + 0x4), *(uint32_t*)(addr + 0x8), *(uint32_t*)(addr + 0xC)); break; } } } else { addr += 0x10; for(i = 0; i < paylen && i < 0x18; i +=2) { len += sprintf(str + len, "%04X ", *(uint16_t*) addr); addr += 2; } } } len += sprintf(str + len, "\n"); if ( gVcDebugMphiDumpMsg ) { printk( KERN_INFO "%s", str ); } MPHI_LOGSTR(drv, str, len); return 0; }
enum video_format video_format_from_fourcc(uint32_t fourcc) { switch (fourcc) { case MAKE_FOURCC('U','Y','V','Y'): case MAKE_FOURCC('H','D','Y','C'): case MAKE_FOURCC('U','Y','N','V'): case MAKE_FOURCC('U','Y','N','Y'): case MAKE_FOURCC('u','y','v','1'): case MAKE_FOURCC('2','v','u','y'): case MAKE_FOURCC('2','V','u','y'): return VIDEO_FORMAT_UYVY; case MAKE_FOURCC('Y','U','Y','2'): case MAKE_FOURCC('Y','4','2','2'): case MAKE_FOURCC('V','4','2','2'): case MAKE_FOURCC('V','Y','U','Y'): case MAKE_FOURCC('Y','U','N','V'): case MAKE_FOURCC('y','u','v','2'): case MAKE_FOURCC('y','u','v','s'): return VIDEO_FORMAT_YUY2; case MAKE_FOURCC('Y','V','Y','U'): return VIDEO_FORMAT_YVYU; } return VIDEO_FORMAT_NONE; }