Пример #1
0
// shutdown
MIDI_RESULT MIDI_Shutdown()
{
    EAS_RESULT result;

    // set flag
    flag = TRUE;

    // join render thread
    pthread_join(thread, NULL);

    // close pcm
    if ((result = snd_pcm_close(handle)) < 0)
    {
	free(buffer);
	EAS_Shutdown(pEASData);
	return result;
    }

    // free buffer
    free(buffer);

    // shutdown library
    if ((result = EAS_Shutdown(pEASData)) < 0)
	return result;

    return MIDI_SUCCESS;
}
    virtual float scoreFactory(const sp<IMediaPlayer>& client,
                               int fd,
                               int64_t offset,
                               int64_t length,
                               float curScore) {
        static const float kOurScore = 0.8;

        if (kOurScore <= curScore)
            return 0.0;

        // Some kind of MIDI?
        EAS_DATA_HANDLE easdata;
        if (EAS_Init(&easdata) == EAS_SUCCESS) {
            EAS_FILE locator;
            locator.path = NULL;
            locator.fd = fd;
            locator.offset = offset;
            locator.length = length;
            EAS_HANDLE  eashandle;
            if (EAS_OpenFile(easdata, &locator, &eashandle) == EAS_SUCCESS) {
                EAS_CloseFile(easdata, eashandle);
                EAS_Shutdown(easdata);
                return kOurScore;
            }
            EAS_Shutdown(easdata);
        }

        return 0.0;
    }
Пример #3
0
//-------------------------------------------------------------------------------------------------
int JetPlayer::release()
{
    LOGV("JetPlayer::release()");
    Mutex::Autolock lock(mMutex);
    mPaused = true;
    mRender = false;
    if (mEasData) {
        JET_Pause(mEasData);
        JET_CloseFile(mEasData);
        JET_Shutdown(mEasData);
        EAS_Shutdown(mEasData);
    }
    if (mEasJetFileLoc) {
        free(mEasJetFileLoc);
        mEasJetFileLoc = NULL;
    }
    if (mAudioTrack) {
        mAudioTrack->stop();
        mAudioTrack->flush();
        delete mAudioTrack;
        mAudioTrack = NULL;
    }
    if (mAudioBuffer) {
        delete mAudioBuffer;
        mAudioBuffer = NULL;
    }
    mEasData = NULL;
    
    return EAS_SUCCESS;
}
static MediaScanResult HandleMIDI(
        const char *filename, MediaScannerClient *client) {
    // get the library configuration and do sanity check
    const S_EAS_LIB_CONFIG* pLibConfig = EAS_Config();
    if ((pLibConfig == NULL) || (LIB_VERSION != pLibConfig->libVersion)) {
        LOGE("EAS library/header mismatch\n");
        return MEDIA_SCAN_RESULT_ERROR;
    }
    EAS_I32 temp;

    // spin up a new EAS engine
    EAS_DATA_HANDLE easData = NULL;
    EAS_HANDLE easHandle = NULL;
    EAS_RESULT result = EAS_Init(&easData);
    if (result == EAS_SUCCESS) {
        EAS_FILE file;
        file.path = filename;
        file.fd = 0;
        file.offset = 0;
        file.length = 0;
        result = EAS_OpenFile(easData, &file, &easHandle);
    }
    if (result == EAS_SUCCESS) {
        result = EAS_Prepare(easData, easHandle);
    }
    if (result == EAS_SUCCESS) {
        result = EAS_ParseMetaData(easData, easHandle, &temp);
    }
    if (easHandle) {
        EAS_CloseFile(easData, easHandle);
    }
    if (easData) {
        EAS_Shutdown(easData);
    }

    if (result != EAS_SUCCESS) {
#ifndef ANDROID_DEFAULT_CODE
        client->setMimeType("bad mime type");
#endif // ANDROID_DEFAULT_CODE
        return MEDIA_SCAN_RESULT_SKIPPED;
    }

    char buffer[20];
    sprintf(buffer, "%ld", temp);
    status_t status = client->addStringTag("duration", buffer);
    if (status != OK) {
        return MEDIA_SCAN_RESULT_ERROR;
    }
#ifndef ANDROID_DEFAULT_CODE
    status_t status_res = client->addStringTag("isAccurateDuration", "1");
    if (status_res) {
    	return MEDIA_SCAN_RESULT_ERROR;
    }
#endif // ANDROID_DEFAULT_CODE

    return MEDIA_SCAN_RESULT_OK;
}
Пример #5
0
MidiEngine::~MidiEngine() {
    if (mEasHandle) {
        EAS_CloseFile(mEasData, mEasHandle);
    }
    if (mEasData) {
        EAS_Shutdown(mEasData);
    }
    delete mGroup;

}
Пример #6
0
static player_type getPlayerType(int fd, int64_t offset, int64_t length)
{
    char buf[20];
    lseek(fd, offset, SEEK_SET);
    read(fd, buf, sizeof(buf));
    lseek(fd, offset, SEEK_SET);

    long ident = *((long*)buf);

    // Ogg vorbis?
    if (ident == 0x5367674f) // 'OggS'
        return VORBIS_PLAYER;

    // Some kind of MIDI?
    EAS_DATA_HANDLE easdata;
    if (EAS_Init(&easdata) == EAS_SUCCESS) {
        EAS_FILE locator;
        locator.path = NULL;
        locator.fd = fd;
        locator.offset = offset;
        locator.length = length;
        EAS_HANDLE  eashandle;
        if (EAS_OpenFile(easdata, &locator, &eashandle) == EAS_SUCCESS) {
            EAS_CloseFile(easdata, eashandle);
            EAS_Shutdown(easdata);
            return SONIVOX_PLAYER;
        }
        EAS_Shutdown(easdata);
    }

#ifdef BUILD_WITH_GST
    // if GST_CONFIG_FILE exists, replace pv player with gst player
    if (access(GST_CONFIG_FILE, 0) == 0)
        return GST_PLAYER;
#endif // BUILD_WITH_GST

    // Fall through to PV
    return PV_PLAYER;
}
Пример #7
0
// shutdown EAS midi
void shutdownEAS()
{
    if (midiHandle != NULL)
    {
	EAS_CloseMIDIStream(pEASData, midiHandle);
	midiHandle = NULL;
    }

    if (pEASData != NULL)
    {
	EAS_Shutdown(pEASData);
	pEASData = NULL;
    }
}
static status_t HandleMIDI(
        const char *filename, MediaScannerClient *client) {
    // get the library configuration and do sanity check
    const S_EAS_LIB_CONFIG* pLibConfig = EAS_Config();
    if ((pLibConfig == NULL) || (LIB_VERSION != pLibConfig->libVersion)) {
        LOGE("EAS library/header mismatch\n");
        return UNKNOWN_ERROR;
    }
    EAS_I32 temp;

    // spin up a new EAS engine
    EAS_DATA_HANDLE easData = NULL;
    EAS_HANDLE easHandle = NULL;
    EAS_RESULT result = EAS_Init(&easData);
    if (result == EAS_SUCCESS) {
        EAS_FILE file;
        file.path = filename;
        file.fd = 0;
        file.offset = 0;
        file.length = 0;
        result = EAS_OpenFile(easData, &file, &easHandle);
    }
    if (result == EAS_SUCCESS) {
        result = EAS_Prepare(easData, easHandle);
    }
    if (result == EAS_SUCCESS) {
        result = EAS_ParseMetaData(easData, easHandle, &temp);
    }
    if (easHandle) {
        EAS_CloseFile(easData, easHandle);
    }
    if (easData) {
        EAS_Shutdown(easData);
    }

    if (result != EAS_SUCCESS) {
        return UNKNOWN_ERROR;
    }

    char buffer[20];
    sprintf(buffer, "%ld", temp);
    if (!client->addStringTag("duration", buffer)) return UNKNOWN_ERROR;

    return OK;
}
status_t MidiFile::getDuration(int* duration)
{

    ALOGV("MidiFile::getDuration");
    {
        Mutex::Autolock lock(mMutex);
        if (!mEasHandle) return ERROR_NOT_OPEN;
        *duration = mDuration;
    }

    // if no duration cached, get the duration
    // don't need a lock here because we spin up a new engine
    if (*duration < 0) {
        EAS_I32 temp;
        EAS_DATA_HANDLE easData = NULL;
        EAS_HANDLE easHandle = NULL;
        EAS_RESULT result = EAS_Init(&easData);
        if (result == EAS_SUCCESS) {
            result = EAS_OpenFile(easData, &mFileLocator, &easHandle);
        }
        if (result == EAS_SUCCESS) {
            result = EAS_Prepare(easData, easHandle);
        }
        if (result == EAS_SUCCESS) {
            result = EAS_ParseMetaData(easData, easHandle, &temp);
        }
        if (easHandle) {
            EAS_CloseFile(easData, easHandle);
        }
        if (easData) {
            EAS_Shutdown(easData);
        }

        if (result != EAS_SUCCESS) {
            return ERROR_EAS_FAILURE;
        }

        // cache successful result
        mDuration = *duration = int(temp);
    }

    return NO_ERROR;
}
status_t MidiFile::release()
{
    ALOGV("MidiFile::release");
    Mutex::Autolock l(mMutex);
    reset_nosync();

    // wait for render thread to exit
    mExit = true;
    mCondition.signal();

    // wait for thread to exit
    if (mAudioBuffer) {
        mCondition.wait(mMutex);
    }

    // release resources
    if (mEasData) {
        EAS_Shutdown(mEasData);
        mEasData = NULL;
    }
    return NO_ERROR;
}
/*----------------------------------------------------------------------------
 * main()
 *----------------------------------------------------------------------------
 * Purpose: The entry point for the EAS sample application
 * 
 * Inputs: 
 *			
 * Outputs:
 *
 *----------------------------------------------------------------------------
*/
int main( int argc, char **argv )
{
	EAS_DATA_HANDLE easData;
	const S_EAS_LIB_CONFIG *pLibConfig;
	void *buffer;
	EAS_RESULT result, playResult;
	EAS_I32 bufferSize;
	int i;
	int temp;
	FILE *debugFile;
	char *outputFile = NULL;

	/* set the error reporting level */
	EAS_SetDebugLevel(_EAS_SEVERITY_INFO);
	debugFile = NULL;

	/* process command-line arguments */
	for (i = 1; i < argc; i++)
	{
		/* check for switch */
		if (argv[i][0] == '-')
		{
			switch (argv[i][1])
			{
			case 'd':
				temp = argv[i][2];
				if ((temp >= '0') || (temp <= '9'))
					EAS_SetDebugLevel(temp);
				else
					{ /* dpp: EAS_ReportEx(_EAS_SEVERITY_WARNING, "Invalid debug level %d\n", temp); */ }
				break;
			case 'f':
				if ((debugFile = fopen(&argv[i][2],"w")) == NULL)
					{ /* dpp: EAS_ReportEx(_EAS_SEVERITY_WARNING, "Unable to create debug file %s\n", &argv[i][2]); */ }
				else
					EAS_SetDebugFile(debugFile, EAS_TRUE);
				break;
			case 'o':
				outputFile = &argv[i][2];
				break;
			case 'p':
				polyphony = atoi(&argv[i][2]);
				if (polyphony < 1)
					polyphony = 1;
				{ /* dpp: EAS_ReportEx(_EAS_SEVERITY_INFO, "Polyphony set to %d\n", polyphony); */ }
				break;
			default:
				break;
			}
			continue;
		}
	}

	/* assume success */
	playResult = EAS_SUCCESS;

	/* get the library configuration */
	pLibConfig = EAS_Config();
	if (!EASLibraryCheck(pLibConfig))
		return -1;
	if (polyphony > pLibConfig->maxVoices)
		polyphony = pLibConfig->maxVoices;

	/* calculate buffer size */
	bufferSize = pLibConfig->mixBufferSize * pLibConfig->numChannels * (EAS_I32)sizeof(EAS_PCM) * NUM_BUFFERS;

	/* allocate output buffer memory */
	buffer = malloc((EAS_U32)bufferSize);
	if (!buffer)
	{
		{ /* dpp: EAS_ReportEx(_EAS_SEVERITY_FATAL, "Error allocating memory for audio buffer\n"); */ }
		return EAS_FAILURE;
	}

	/* initialize the EAS library */
	polyphony = pLibConfig->maxVoices;
	if ((result = EAS_Init(&easData)) != EAS_SUCCESS)
	{
		{ /* dpp: EAS_ReportEx(_EAS_SEVERITY_FATAL, "EAS_Init returned %ld - aborting!\n", result); */ }
		free(buffer);
		return result;
	}

	/*
	 * Some debugging environments don't allow for passed parameters.
	 * In this case, just play the default MIDI file "test.mid"
	 */
	if (argc < 2)
	{
		{ /* dpp: EAS_ReportEx(_EAS_SEVERITY_INFO, "Playing '%s'\n", defaultTestFile); */ }
		if ((playResult = PlayFile(easData, defaultTestFile, NULL, pLibConfig, buffer, bufferSize)) != EAS_SUCCESS)
		{
			{ /* dpp: EAS_ReportEx(_EAS_SEVERITY_ERROR, "Error %d playing file %s\n", playResult, defaultTestFile); */ }
		}
	}
	/* iterate through the list of files to be played */
	else
	{
		for (i = 1; i < argc; i++)
		{
			/* check for switch */
			if (argv[i][0] != '-')
			{

				{ /* dpp: EAS_ReportEx(_EAS_SEVERITY_INFO, "Playing '%s'\n", argv[i]); */ }
				if ((playResult = PlayFile(easData, argv[i], outputFile, pLibConfig, buffer, bufferSize)) != EAS_SUCCESS)
				{
					{ /* dpp: EAS_ReportEx(_EAS_SEVERITY_ERROR, "Error %d playing file %s\n", playResult, argv[i]); */ }
					break;
				}
			}
		}
	}

	/* shutdown the EAS library */
	if ((result = EAS_Shutdown(easData)) != EAS_SUCCESS)
	{
		{ /* dpp: EAS_ReportEx(_EAS_SEVERITY_FATAL, "EAS_Shutdown returned %ld\n", result); */ }
	}

	/* free the output buffer */
	free(buffer);

	/* close the debug file */
	if (debugFile)
		fclose(debugFile);

	/* play errors take precedence over shutdown errors */
	if (playResult != EAS_SUCCESS)
		return playResult;
	return result;
} /* end main */
player_type getPlayerType_l(int fd, int64_t offset, int64_t length, bool check_cedar)
{
	int r_size;
	int file_format;
    char buf[4096];
    lseek(fd, offset, SEEK_SET);
    r_size = read(fd, buf, sizeof(buf));
    lseek(fd, offset, SEEK_SET);

    long ident = *((long*)buf);

    // Ogg vorbis?
    if (ident == 0x5367674f) // 'OggS'
        return STAGEFRIGHT_PLAYER;

    // Some kind of MIDI?
    EAS_DATA_HANDLE easdata;
    if (EAS_Init(&easdata) == EAS_SUCCESS) {
        EAS_FILE locator;
        locator.path = NULL;
        locator.fd = fd;
        locator.offset = offset;
        locator.length = length;
        EAS_HANDLE  eashandle;
        if (EAS_OpenFile(easdata, &locator, &eashandle) == EAS_SUCCESS) {
            EAS_CloseFile(easdata, eashandle);
            EAS_Shutdown(easdata);
            return SONIVOX_PLAYER;
        }
        EAS_Shutdown(easdata);
    }

    if (check_cedar) {
		file_format = audio_format_detect((unsigned char*)buf, r_size, fd, offset);
		ALOGV("getPlayerType: %d",file_format);

        if (file_format == MEDIA_FORMAT_MKV) {
            bool ret = MkvGetCodecId(fd, offset, length);
            if (ret) {
                return STAGEFRIGHT_PLAYER;
            }
            else {
                return CEDARX_PLAYER;
            }
        }
        else if (file_format == MEDIA_FORMAT_3GP) {
            return STAGEFRIGHT_PLAYER;
        }
        else if (file_format == MEDIA_FORMAT_M4A)
        {
			int audio_only;
			audio_only = MovAudioOnlyDetect1(fd, offset, length);
			lseek(fd, offset, SEEK_SET);

			return audio_only ? STAGEFRIGHT_PLAYER : CEDARX_PLAYER;
		}
		else
		{
			if(file_format < MEDIA_FORMAT_STAGEFRIGHT_MAX && file_format > MEDIA_FORMAT_STAGEFRIGHT_MIN){
				ALOGV("use STAGEFRIGHT_PLAYER");
				return STAGEFRIGHT_PLAYER;
			}
			else if(file_format < MEDIA_FORMAT_CEDARA_MAX && file_format > MEDIA_FORMAT_CEDARA_MIN){
				ALOGV("use CEDARA_PLAYER");
				return CEDARA_PLAYER;
			}
			else if(file_format < MEDIA_FORMAT_CEDARX_MAX && file_format > MEDIA_FORMAT_CEDARX_MIN){
				ALOGV("use CEDARX_PLAYER");
				return CEDARX_PLAYER;
			}
		}
    }

    //return STAGEFRIGHT_PLAYER; 
    return CEDARX_PLAYER;
}