示例#1
0
/**
 * Creates a Media Source Reader.
 *
 * @param env JNI env
 * @param path path
 * @param ppMediaSrcReader media source reader
 * @return HRESULT
 */
HRESULT mf_createMediaSourceReader(JNIEnv *env, jstring path, IMFSourceReader **ppMediaSrcReader) {

    HRESULT res = S_OK;
    const LPWSTR pwszFilePath = (LPWSTR)env->GetStringChars(path, NULL);

    res = MFCreateSourceReaderFromURL(
        pwszFilePath, 
        NULL, 
        ppMediaSrcReader);
	if (HRESULT_CODE(res) == ERROR_FILE_NOT_FOUND
			|| HRESULT_CODE(res) == ERROR_PATH_NOT_FOUND
			|| HRESULT_CODE(res) == ERROR_NOT_DOS_DISK
			|| HRESULT_CODE(res) == ERROR_BAD_NETPATH) {
		const char * filePath = env->GetStringUTFChars(path, NULL);
        throwFileNotFoundExceptionIfError(env, res, filePath);
	    env->ReleaseStringUTFChars(path, filePath);
        goto bail;
	}
    if (res != S_OK) {
        throwUnsupportedAudioFileExceptionIfError(env, res, "Failed to create source reader from url");
        goto bail;
    }

bail:

    env->ReleaseStringChars(path, (jchar *)pwszFilePath);

    return res;
}
示例#2
0
/**
 * Opens the input file/url and allocates a AVFormatContext for it, but does not open the audio stream with an
 * appropriate decoder.
 *
 * @param env JNIEnv
 * @param format_context AVFormatContext
 * @param url URL to open
 * @return negative value, if something went wrong
 */
int ff_open_format_context(JNIEnv *env, AVFormatContext **format_context, const char *url) {
    int res = 0;
    int probe_score = 0;

    res = avformat_open_input(format_context, url, NULL, NULL);
    if (res) {
        if (res == AVERROR(ENOENT) || res == AVERROR_HTTP_NOT_FOUND) {
            throwFileNotFoundExceptionIfError(env, res, url);
        } else if (res == AVERROR_PROTOCOL_NOT_FOUND
                || res == AVERROR_HTTP_BAD_REQUEST
                || res == AVERROR_HTTP_UNAUTHORIZED
                || res == AVERROR_HTTP_FORBIDDEN
                || res == AVERROR_HTTP_OTHER_4XX
                || res == AVERROR_HTTP_SERVER_ERROR
                || res == AVERROR(EIO)) {
            throwIOExceptionIfError(env, res, url);
        } else {
            throwUnsupportedAudioFileExceptionIfError(env, res, "Failed to open audio file");
        }
        goto bail;
    }
    probe_score = av_format_get_probe_score(*format_context);

    #ifdef DEBUG
        fprintf(stderr, "ff_open_format_context(): probe score=%i\n", probe_score);
    #endif

    if (probe_score < MIN_PROBE_SCORE) {
        res = probe_score;
        throwUnsupportedAudioFileExceptionIfError(env, probe_score, "Probe score too low");
        goto bail;
    }

    res = avformat_find_stream_info(*format_context, NULL);
    if (res < 0) {
        throwUnsupportedAudioFileExceptionIfError(env, res, "Failed to find stream info");
        goto bail;
    }

bail:

    return res;
}