📄 main.cpp
字号:
ASSERT (idx >= 0); release_buffer (&(BP->B[idx])); return 0;}static RMuint32 mp4_info (RMint32 msg, void *info, void *context){ if (msg == MP4_MSG_TRACK_TIMESCALE) { TRACK_TIMESCALE *ts; ts = (TRACK_TIMESCALE *)info; videoTimeScale = ts->videoTimeScale; audioTimeScale = ts->audioTimeScale[0]; DEBUGMSG (1, ("videoTimeScale = %d\n", (RMint32)videoTimeScale)); DEBUGMSG (1, ("audioTimeScale = %d\n", (RMint32)audioTimeScale)); } else if (msg == MP4_MSG_VIDEO_DIMENSIONS) { RMint32 w, h, n, d, x, y; VIDEO_DIMENSIONS *vd; vd = (VIDEO_DIMENSIONS *)info; ASSERT (pMpegDecoder); pMpegDecoder->GetScreenDimensions (&w, &h, &n, &d); DEBUGMSG (1, ("%d x %d\n", vd->visualWidth, vd->visualHeight)); if ((vd->visualWidth*1000*d/(w*n)) > vd->visualHeight*1000/h) { ASSERT (d); ASSERT (vd->visualWidth); y = (vd->visualHeight * w / vd->visualWidth) * n / d; ASSERT (y <= h); x = (h - y) / 2; ASSERT (x >= 0); ASSERT (w > 0); ASSERT (y > 0); DEBUGMSG (!(x >= 0) || !(w > 0) || !(y > 0), ("x = %d, y = %d, w = %d, h = %d\n", x, y, w, h)); DEBUGMSG (1, ("(%d, %d, %d, %d)\n", 0, x, w, y)); pMpegDecoder->SetVideoDestination (0, x, w, y); } else { ASSERT (d); ASSERT (vd->visualHeight); y = (vd->visualWidth * h / vd->visualHeight) * d / n; ASSERT (y <= w); x = (w - y) / 2; ASSERT (x >= 0); DEBUGMSG (!(x >= 0) || !(y > 0) || !(h > 0), ("x = %d, y = %d, w = %d, h = %d\n", x, y, w, h)); ASSERT (y > 0); ASSERT (h > 0); DEBUGMSG (1, ("(%d, %d, %d, %d)\n", x, 0, y, h)); pMpegDecoder->SetVideoDestination (x, 0, y, h); } } else { DEBUGMSG (1, ("message %d not implemented\n", msg)); ASSERT (0); } return 0;}static RMuint32 mp4_getData (RMuint8 **pBuffer, RMuint32 *length, void *context){ int idx = find_free_buffer (&BPmp4, 0); if (idx < 0) { if (PreBuffering) { pMpegDecoder->Play (); PreBuffering = 0; DEBUGMSG (1, ("play due to mp4 buffer full\n")); } return 1; } *length = (RMuint32)BPmp4.buffers_size; *pBuffer = (RMuint8 *)get_buffer_address (&BPmp4, idx); DEBUGMSG (0, ("(%d)", idx)); return 0;}static RMint32 ParseVOLHdr (RMuint8 *pDSI, RMuint32 length){ int Error = 0; BitStream DSIInformation (pDSI, length, &Error); RMuint32 vop_time_increment_resolution; RMuint32 temp; vopTimeIncrRes = 30000; while (1) { temp = DSIInformation.showbits(32); if ((temp >= 0x00000100) && (temp <= 0x0000011F)) break; temp = DSIInformation.getbits (8, &Error); // USER_DATA_START_CODE, user data if (Error) { DEBUGMSG (1, ("ParseDSIInformation: NO video object start code\n")); return -1; } } temp = DSIInformation.getbits (32, &Error); // video_object_start_code temp = DSIInformation.showbits (32); // video_object_layer_start_code if ((temp & 0x000001E0) == 0x00000120) { // short_video_header = 0 temp = DSIInformation.getbits (32, &Error); // video_object_layer_start_code temp = DSIInformation.getbits (1, &Error); // random_accessible_vol temp = DSIInformation.getbits (8, &Error); // video_object_type_indication temp = DSIInformation.getbits (1, &Error); // is_object_layer_identifier if (temp == 1) { temp = DSIInformation.getbits (4, &Error); // video_object_layer_verid should be 1 temp = DSIInformation.getbits (3, &Error); // video_object_layer_priority } temp = DSIInformation.getbits (4, &Error); // aspect_ratio_info if (temp == 0xf) // extended par { RMuint32 par_width = DSIInformation.getbits (8, &Error); // par_width RMuint32 par_height = DSIInformation.getbits (8, &Error); // par_height pixel_aspect_ratio_x = par_width; pixel_aspect_ratio_y = par_height; } else { switch (temp) { case 2: pixel_aspect_ratio_x = 12; pixel_aspect_ratio_y = 11; break; case 3: pixel_aspect_ratio_x = 10; pixel_aspect_ratio_y = 11; break; case 4: pixel_aspect_ratio_x = 16; pixel_aspect_ratio_y = 11; break; case 5: pixel_aspect_ratio_x = 40; pixel_aspect_ratio_y = 33; break; default: pixel_aspect_ratio_x = 1; pixel_aspect_ratio_y = 1; break; } } temp = DSIInformation.getbits (1, &Error); // vol_control_parameters if (temp == 1) { temp = DSIInformation.getbits (2, &Error); // chroma_format temp = DSIInformation.getbits (1, &Error); // low_delay temp = DSIInformation.getbits (1, &Error); // vbv_parameters if (temp == 1) { temp = DSIInformation.getbits (15, &Error);// first_half_bit_rate temp = DSIInformation.getbits (1, &Error); // marker_bit temp = DSIInformation.getbits (15, &Error);// latter_half_bit_rate temp = DSIInformation.getbits (1, &Error); // marker_bit temp = DSIInformation.getbits (15, &Error);// first_half_vbv_buffer_size temp = DSIInformation.getbits (1, &Error); // marker_bit temp = DSIInformation.getbits (3, &Error); // latter_half_vbv_buffer_size temp = DSIInformation.getbits (11, &Error);// first_half_vbv_occupancy temp = DSIInformation.getbits (1, &Error); // marker_bit temp = DSIInformation.getbits (15, &Error);// latter_half_vbv_occupancy temp = DSIInformation.getbits (1, &Error); // marker_bit } } RMuint8 video_object_layer_shape = DSIInformation.getbits (2, &Error); temp = DSIInformation.getbits (1, &Error); // marker_bit vop_time_increment_resolution = DSIInformation.getbits (16, &Error); DEBUGMSG (0, ("vop_time_increment_resolution = %d\n", vop_time_increment_resolution)); temp = DSIInformation.getbits (1, &Error); // marker_bit temp = DSIInformation.getbits (1, &Error); // fixed_vop_rate if (temp) { DEBUGMSG (0, ("fixed_vop_rate\n")); RMint32 nbits; for (nbits=16; nbits>0; nbits--) { if ((vop_time_increment_resolution >> nbits) == 1) break; } nbits++; RMint32 fixed_vop_time_increment = DSIInformation.getbits (nbits, &Error); DEBUGMSG (0, ("fixed_vop_time_increment = %d\n", fixed_vop_time_increment)); fixedvopRate = fixed_vop_time_increment; } else fixedvopRate = 0; vopTimeIncrRes = vop_time_increment_resolution; if (video_object_layer_shape == 0) // Rectangular { temp = DSIInformation.getbits(1,&Error); // marker_bit temp = DSIInformation.getbits(13,&Error); // width temp = DSIInformation.getbits(1,&Error); // marker_bit temp = DSIInformation.getbits(13,&Error); // height } else return 0; return 0; } else return -1;}static RMuint32 mp4_putDSI (RMuint32 trackid, RMuint32 flags, RMuint8 *pBuffer, RMuint32 length, RMuint64 time, void *context){ MPEG_DECODER_ERROR mpegerr; DEBUGMSG (0, ("putDSI:\n")); DEBUGMSG (0, (" trackid %d: %lu @ 0x%08lx\n", (int)trackid, (RMuint32)length, (RMuint32)pBuffer)); if (trackid == 0) { if (fout) { fwrite (pBuffer, 1, length, fout); return 0; } int idx = find_free_buffer (&BPmp4, 0); if (idx < 0) { return 1; } RMuint32 l; RMuint8 *p; l = (RMuint32)BPmp4.buffers_size; p = (RMuint8 *)get_buffer_address (&BPmp4, idx); ASSERT (l > length); ASSERT (p); ParseVOLHdr (pBuffer, length); mp4_scrDelay = 0; MPEGVIDEO_PARAMETERS videoparams; videoparams.isMPEG4 = 1; videoparams.vopTimeIncrRes = vopTimeIncrRes; videoparams.videoTimeScale = vopTimeIncrRes; videoparams.audioTimeScale = vopTimeIncrRes; if (fixedvopRate) { videoparams.fixedVOPRate = 1; videoparams.vopTimeIncr = fixedvopRate; } else { videoparams.fixedVOPRate = 0; videoparams.vopTimeIncr = 0; } DEBUGMSG (1, ("MP4:\n")); DEBUGMSG (1, ("vopTimeIncrRes: %lu\n", videoparams.vopTimeIncrRes)); DEBUGMSG (1, ("videoTimeScale: %lu\n", videoparams.videoTimeScale)); DEBUGMSG (1, ("audioTimeScale: %lu\n", videoparams.audioTimeScale)); DEBUGMSG (1, ("fixedVOPRate: %lu\n", videoparams.fixedVOPRate)); DEBUGMSG (1, ("vopTimeIncr: %lu\n", videoparams.vopTimeIncr)); pMpegDecoder->SetMpegVideoParameters (&videoparams); pMpegDecoder->Pause (); PreBuffering = 1; mp4_scr0 = time * vopTimeIncrRes / videoTimeScale; DEBUGMSG (1, ("mp4_scr0: %d\n", (int)mp4_scr0)); memcpy (p, pBuffer, length); addref_buffer (&(BPmp4.B[idx])); mpegerr = pMpegDecoder->WriteMpegVideo (p, length, &(BPmp4.B[idx]), 0, 0, 0); ASSERT (mpegerr == MPEG_DECODER_ERROR_NO_ERROR); } else if (trackid == 1) { cts_counter = 0; ASSERT (pAACDecoder); if (pAACDecoder->dsiInit (pBuffer, length) == AAC_SUCCESS) {#ifdef KERNEL_MODULE_SUPPORTS_AAC // even though we use hardware to decode, we still use // the software library to parse the DSI to get the // sampling frequency and channel count. // If you wanted to save some memory it is quite easy // to write an audio DSI parser. In this case, there // would be no need to link to the software aac decoder // library. AAC_PARAMETERS aacparams; aacparams.SamplesPerSecond = pAACDecoder->m_sampleRate; aacparams.NumberOfChannels = pAACDecoder->m_channelCount; // we must inform the decoder of the format of incoming aac stream#ifdef REFORMAT_AAC_TO_ADTS // an ADTS stream aacparams.AACType = AAC_TYPE_ADTS;#else // a DSI stream (dsi header, then raw data blocks) aacparams.AACType = AAC_TYPE_DSI;#endif pMpegDecoder->SetAACParameters (&aacparams); adtshdrlength = 0;#ifdef REFORMAT_AAC_TO_ADTS // create a static ADTS header that will be prepended to all aac frames RMint32 id, layer, protection_absent, profile, sf_index, private_bit, channel_config, original_copy, home; BitBuffer adtshdr (aacframe, sizeof (aacframe)); adtshdr.putbits (0xfff, 12); id = 1; adtshdr.putbits (id, 1); layer = 0; // XXX assume mpeg-4? adtshdr.putbits (layer, 2); protection_absent = 1; adtshdr.putbits (protection_absent, 1); profile = 1; adtshdr.putbits (profile, 2); sf_index = pAACDecoder->m_sample_frequency_index; adtshdr.putbits (sf_index, 4); private_bit = 1; adtshdr.putbits (private_bit, 1); channel_config = 2; adtshdr.putbits (channel_config, 3); original_copy = 0; adtshdr.putbits (original_copy, 1); home = 0; adtshdr.putbits (home, 1); adtshdr.putbits (0, 1); adtshdr.putbits (0, 1); adtshdr.putbits (1024, 13); // XXX does the decoder care for this parameter? adtshdr.putbits (1024, 11); // XXX does the decoder care for this parameter? adtshdr.putbits (1, 2); adtshdrlength = adtshdr.numbits () / 8; if (adtshdr.numbits () % 8) adtshdrlength++; DEBUGMSG (1, ("adtshdrlength = %d\n", (int)adtshdrlength));#else // create a DSI header that is delivered only ONCE at the start aacframe[0] = (RMuint8)(length >> 24); aacframe[1] = (RMuint8)(length >> 16); aacframe[2] = (RMuint8)(length >> 8); aacframe[3] = (RMuint8)(length >> 0); memcpy (aacframe+4, pBuffer, length); DEBUGMSG (0, ("[dsi] WriteAAC (%08lx, %d)\n", (RMuint32)pBuffer, (int)(length+4))); mpegerr = pMpegDecoder->WriteAAC (aacframe, length+4, 0, 0, 0, 0); ASSERT (mpegerr == MPEG_DECODER_ERROR_NO_ERROR);#endif#else // XXX should do error handing (wrong sampling rate, nchannels) PCM_PARAMETERS pcmparams; pcmparams.NumberOfBitsPerSample = 16; pcmparams.NumberOfChannels = pAACDecoder->m_channelCount; pcmparams.SamplesPerSecond = pAACDecoder->m_sampleRate; pMpegDecoder->SetPCMParameters (&pcmparams);#endif DEBUGMSG (1, ("NumberOfChannels = %d\n", (int)pAACDecoder->m_channelCount)); DEBUGMSG (1, ("SamplesPerSecond = %d\n", (int)pAACDecoder->m_sampleRate)); } else { // XXX should do error handing ASSERT (0); } } return 0;}static RMuint32 mp4_putChunk (RMuint32 trackid, RMuint32 flags, RMuint64 time, RMuint8 *pBuffer, RMuint32 length, void *context){ MPEG_DECODER_ERROR mpegerr; RMint32 n, aaclen; DEBUGMSG (0, ("putChunk:\n")); DEBUGMSG (0, (" trackid %d: %lu @ 0x%08lx\n", (int)trackid, (RMuint32)length, (RMuint32)pBuffer)); if (length == 0) return 0; if (trackid == 0) { if (flags & CHUNK_FLAGS_TIME_VALID) { time = time * vopTimeIncrRes / videoTimeScale;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -