ref: 6ca72a90fc5ab19a40f74b544e153bf62e95f7a3
parent: 97334a539e561699d0c296fe51e8c50a86fd9998
author: ca5e <ca5e>
date: Fri Oct 17 13:11:38 EDT 2003
Gapless mode change
--- a/plugins/in_mp4/in_mp4.c
+++ b/plugins/in_mp4/in_mp4.c
@@ -22,7 +22,7 @@
** Commercial non-GPL licensing of this software is possible.
** For more info contact Ahead Software through [email protected].
**
-** $Id: in_mp4.c,v 1.42 2003/10/12 13:30:06 ca5e Exp $
+** $Id: in_mp4.c,v 1.43 2003/10/17 17:11:38 ca5e Exp $
**/
//#define DEBUG_OUTPUT
@@ -1431,304 +1431,6 @@
return 0;
}
-
-
-
-
-
-#if 0
-int play(char *fn)
-{
- int maxlatency;
- int thread_id;
- int avg_bitrate, br, sr;
- unsigned char *buffer;
- int buffer_size;
- faacDecConfigurationPtr config;
-
-#ifdef DEBUG_OUTPUT
- in_mp4_DebugOutput("play");
-#endif
-
- memset(&mp4state, 0, sizeof(state));
-
- lstrcpy(mp4state.filename, fn);
-
- if (!(mp4state.mp4file = MP4Read(mp4state.filename, 0)))
- {
- mp4state.filetype = 1;
- } else {
- MP4Close(mp4state.mp4file);
- mp4state.filetype = 0;
- }
-
- mp4state.hDecoder = faacDecOpen();
- if (!mp4state.hDecoder)
- {
- show_error(module.hMainWindow, "Unable to open decoder library.");
- return -1;
- }
-
- config = faacDecGetCurrentConfiguration(mp4state.hDecoder);
- config->outputFormat = m_resolution + 1;
- config->downMatrix = m_downmix;
- faacDecSetConfiguration(mp4state.hDecoder, config);
-
- if (mp4state.filetype)
- {
- int tagsize = 0, tmp = 0;
- int bread = 0;
- double length = 0.;
- __int64 bitrate = 128;
- faacDecFrameInfo frameInfo;
-
- module.is_seekable = 1;
-
- if (!(mp4state.aacfile = fopen(mp4state.filename, "rb")))
- {
- // error
- return 0;
- }
-
- mp4state.m_at_eof = 0;
-
- if (!(mp4state.m_aac_buffer = (unsigned char*)malloc(768*6)))
- {
- show_error(module.hMainWindow, "Memory allocation error.");
- return 0;
- }
- memset(mp4state.m_aac_buffer, 0, 768*6);
-
- bread = fread(mp4state.m_aac_buffer, 1, 768*6, mp4state.aacfile);
- mp4state.m_aac_bytes_into_buffer = bread;
- mp4state.m_aac_bytes_consumed = 0;
- mp4state.m_file_offset = 0;
-
- if (bread != 768*6)
- mp4state.m_at_eof = 1;
-
- if (!memcmp(mp4state.m_aac_buffer, "ID3", 3))
- {
- /* high bit is not used */
- tagsize = (mp4state.m_aac_buffer[6] << 21) | (mp4state.m_aac_buffer[7] << 14) |
- (mp4state.m_aac_buffer[8] << 7) | (mp4state.m_aac_buffer[9] << 0);
-
- tagsize += 10;
- advance_buffer(&mp4state, tagsize);
- }
-
- mp4state.m_head = (struct seek_list*)malloc(sizeof(struct seek_list));
- mp4state.m_tail = mp4state.m_head;
- mp4state.m_tail->next = NULL;
-
- mp4state.m_header_type = 0;
- if ((mp4state.m_aac_buffer[0] == 0xFF) && ((mp4state.m_aac_buffer[1] & 0xF6) == 0xF0))
- {
- if (1) //(can_seek)
- {
- adts_parse(&mp4state, &bitrate, &length);
- fseek(mp4state.aacfile, tagsize, SEEK_SET);
-
- bread = fread(mp4state.m_aac_buffer, 1, 768*6, mp4state.aacfile);
- if (bread != 768*6)
- mp4state.m_at_eof = 1;
- else
- mp4state.m_at_eof = 0;
- mp4state.m_aac_bytes_into_buffer = bread;
- mp4state.m_aac_bytes_consumed = 0;
-
- mp4state.m_header_type = 1;
- }
- } else if (memcmp(mp4state.m_aac_buffer, "ADIF", 4) == 0) {
- int skip_size = (mp4state.m_aac_buffer[4] & 0x80) ? 9 : 0;
- bitrate = ((unsigned int)(mp4state.m_aac_buffer[4 + skip_size] & 0x0F)<<19) |
- ((unsigned int)mp4state.m_aac_buffer[5 + skip_size]<<11) |
- ((unsigned int)mp4state.m_aac_buffer[6 + skip_size]<<3) |
- ((unsigned int)mp4state.m_aac_buffer[7 + skip_size] & 0xE0);
-
- length = (double)file_length(mp4state.aacfile);
- if (length == -1)
- {
- module.is_seekable = 0;
- length = 0;
- } else {
- length = ((double)length*8.)/((double)bitrate) + 0.5;
- }
-
- mp4state.m_header_type = 2;
- } else {
- length = (double)file_length(mp4state.aacfile);
- length = ((double)length*8.)/((double)bitrate*1000.) + 0.5;
-
- module.is_seekable = 1;
- }
-
- mp4state.m_length = (int)(length*1000.);
-
- fill_buffer(&mp4state);
- if ((mp4state.m_aac_bytes_consumed = faacDecInit(mp4state.hDecoder,
- mp4state.m_aac_buffer, mp4state.m_aac_bytes_into_buffer,
- &mp4state.samplerate, &mp4state.channels)) < 0)
- {
- show_error(module.hMainWindow, "Can't initialize decoder library.");
- return 0;
- }
- advance_buffer(&mp4state, mp4state.m_aac_bytes_consumed);
-
- if (mp4state.m_header_type == 2)
- avg_bitrate = bitrate;
- else
- avg_bitrate = bitrate*1000;
-
- decode_aac_frame(&mp4state, &frameInfo);
- mp4state.channels = frameInfo.channels;
- mp4state.samplerate = frameInfo.samplerate;
-
- } else {
- mp4state.mp4file = MP4Read(mp4state.filename, 0);
- if (!mp4state.mp4file)
- {
- show_error(module.hMainWindow, "Unable to open file.");
- faacDecClose(mp4state.hDecoder);
- return -1;
- }
-
- if ((mp4state.mp4track = GetAACTrack(mp4state.mp4file)) < 0)
- {
- show_error(module.hMainWindow, "Unsupported Audio track type.");
- faacDecClose(mp4state.hDecoder);
- MP4Close(mp4state.mp4file);
- return -1;
- }
-
- buffer = NULL;
- buffer_size = 0;
- MP4GetTrackESConfiguration(mp4state.mp4file, mp4state.mp4track,
- &buffer, &buffer_size);
- if (!buffer)
- {
- faacDecClose(mp4state.hDecoder);
- MP4Close(mp4state.mp4file);
- return -1;
- }
-
- if(faacDecInit2(mp4state.hDecoder, buffer, buffer_size,
- &mp4state.samplerate, &mp4state.channels) < 0)
- {
- /* If some error initializing occured, skip the file */
- faacDecClose(mp4state.hDecoder);
- MP4Close(mp4state.mp4file);
- return -1;
- }
-
- /* for gapless decoding */
- {
- mp4AudioSpecificConfig mp4ASC;
-
- mp4state.timescale = MP4GetTrackTimeScale(mp4state.mp4file, mp4state.mp4track);
- mp4state.framesize = 1024;
- mp4state.useAacLength = 0;
-
- if (buffer)
- {
- if (AudioSpecificConfig(buffer, buffer_size, &mp4ASC) >= 0)
- {
- if (mp4ASC.frameLengthFlag == 1) mp4state.framesize = 960;
- if (mp4ASC.sbr_present_flag == 1) mp4state.framesize *= 2;
- }
- }
- }
-
- free(buffer);
-
- avg_bitrate = MP4GetTrackIntegerProperty(mp4state.mp4file, mp4state.mp4track,
- "mdia.minf.stbl.stsd.mp4a.esds.decConfigDescr.avgBitrate");
-
- mp4state.numSamples = MP4GetTrackNumberOfSamples(mp4state.mp4file, mp4state.mp4track);
- mp4state.sampleId = 1;
-
- module.is_seekable = 1;
- }
-
- if (mp4state.channels == 0)
- {
- show_error(module.hMainWindow, "Number of channels not supported for playback.");
- faacDecClose(mp4state.hDecoder);
- if (mp4state.filetype)
- fclose(mp4state.aacfile);
- else
- MP4Close(mp4state.mp4file);
- return -1;
- }
-
- if (m_downmix && (mp4state.channels == 5 || mp4state.channels == 6))
- mp4state.channels = 2;
-
- maxlatency = module.outMod->Open(mp4state.samplerate, (int)mp4state.channels,
- res_table[m_resolution], -1, -1);
-
- if (maxlatency < 0) // error opening device
- {
- faacDecClose(mp4state.hDecoder);
- if (mp4state.filetype)
- fclose(mp4state.aacfile);
- else
- MP4Close(mp4state.mp4file);
- return -1;
- }
-
- mp4state.paused = 0;
- mp4state.decode_pos_ms = 0;
- mp4state.seek_needed = -1;
-
- // initialize vis stuff
- module.SAVSAInit(maxlatency, mp4state.samplerate);
- module.VSASetInfo((int)mp4state.channels, mp4state.samplerate);
-
- br = (int)floor(((float)avg_bitrate + 500.0)/1000.0 + 0.5);
- sr = (int)floor((float)mp4state.samplerate/1000.0 + 0.5);
- module.SetInfo(br, sr, (int)mp4state.channels, 1);
-
- module.outMod->SetVolume(-666); // set the output plug-ins default volume
-
- killPlayThread = 0;
-
- if (mp4state.filetype)
- {
- if ((play_thread_handle = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)AACPlayThread,
- (void *)&killPlayThread, 0, &thread_id)) == NULL)
- {
- show_error(module.hMainWindow, "Cannot create playback thread");
- faacDecClose(mp4state.hDecoder);
- fclose(mp4state.aacfile);
- return -1;
- }
- } else {
- if ((play_thread_handle = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)MP4PlayThread,
- (void *)&killPlayThread, 0, &thread_id)) == NULL)
- {
- show_error(module.hMainWindow, "Cannot create playback thread");
- faacDecClose(mp4state.hDecoder);
- MP4Close(mp4state.mp4file);
- return -1;
- }
- }
-
- SetThreadAffinityMask(play_thread_handle, 1);
-
- SetThreadPriority(play_thread_handle, priority_table[m_priority]);
-
- return 0;
-}
-#endif
-
-
-
-
-
-
-
-
void pause()
{
#ifdef DEBUG_OUTPUT
@@ -2100,6 +1802,7 @@
rc = MP4ReadSample(mp4state.mp4file, mp4state.mp4track,
mp4state.sampleId++, &buffer, &buffer_size,
NULL, &dur, NULL, NULL);
+ if (mp4state.sampleId-1 == 1) dur = 0;
if (rc == 0 || buffer == NULL)
{
mp4state.last_frame = 1;