Exemplo n.º 1
0
/**
 * initialize the media player
 *
 * @param  channel    opaque handle returned by WTSVirtualChannelOpenEx
 * @param  stream_id  unique identification number for this stream
 * @param  filename   media file to play
 *
 * @return  0 on success, -1 on error
 *****************************************************************************/
int
xrdpvr_init_player(void *channel, int stream_id, char *filename)
{
    if ((channel == NULL) || (stream_id <= 0) || (filename == NULL))
    {
        return -1;
    }

    /* send metadata from media file to client */
    if (xrdpvr_create_metadata_file(channel, filename))
    {
        printf("error sending metadata to client\n");
        return -1;
    }

    /* ask client to get video format from media file */
    if (xrdpvr_set_video_format(channel, 101))
    {
        printf("xrdpvr_set_video_format() failed\n");
        return -1;
    }

    /* TODO */
    sleep(3);

    /* ask client to get audio format from media file */
    if (xrdpvr_set_audio_format(channel, 101))
    {
        printf("xrdpvr_set_audio_format() failed\n");
        return 1;
    }
}
Exemplo n.º 2
0
int OurInterface::sendAudioFormat()
{
    if (xrdpvr_set_audio_format(channel, stream_id))
    {
        emit on_ErrorMsg("I/O Error",
                         "Error sending audio format to remote client");
        return -1;
    }

    return 0;
}
Exemplo n.º 3
0
/**
 * play the media
 *
 * @param  channel    opaque handle returned by WTSVirtualChannelOpenEx
 * @param  stream_id  unique identification number for this stream
 * @param  filename   media file to play
 *
 * @return  0 on success, -1 on error
 *****************************************************************************/
int
xrdpvr_play_media(void *channel, int stream_id, char *filename)
{
    int i;

    printf("$$$$$$ xrdpvr_play_media: setting audioTimeout & "
           "videoTimeout to -1\n");
    g_psi.videoTimeout = -1;
    g_psi.audioTimeout = -1;

    /* register all available fileformats and codecs */
    av_register_all();

    /* open media file - this will read just the header */
    //if (avformat_open_input(&g_psi.p_format_ctx, filename, NULL, NULL))
    if (av_open_input_file(&g_psi.p_format_ctx, filename, NULL, 0, NULL))
    {
        printf("ERROR opening %s\n", filename);
        return -1;
    }

    /* now get the real stream info */
    //if (avformat_find_stream_info(g_psi.p_format_ctx, NULL) < 0)
    if (av_find_stream_info(g_psi.p_format_ctx) < 0)
    {
        printf("ERROR reading stream info\n");
        return -1;
    }

#if 1
    /* print media info to standard out */
    av_dump_format(g_psi.p_format_ctx, 0, filename, 0);
#endif

    printf("nb_streams %d\n", g_psi.p_format_ctx->nb_streams);

    g_audio_index = -1;
    g_video_index = -1;

    /* find first audio / video stream */
    for (i = 0; i < g_psi.p_format_ctx->nb_streams; i++)
    {
        if (g_psi.p_format_ctx->streams[i]->codec->codec_type ==
                CODEC_TYPE_VIDEO &&
                g_psi.p_format_ctx->streams[i]->codec->codec_id ==
                CODEC_ID_H264 &&
                g_video_index < 0)
        {
            g_video_index = i;
        }

        if (g_psi.p_format_ctx->streams[i]->codec->codec_type ==
                CODEC_TYPE_AUDIO &&
                g_psi.p_format_ctx->streams[i]->codec->codec_id ==
                CODEC_ID_AAC &&
                g_audio_index < 0)
        {
            g_audio_index = i;
        }
    }

    if ((g_audio_index < 0) || (g_video_index < 0))
    {
        /* close file and return with error */
        printf("ERROR: no audio/video stream found in %s\n", filename);
        //avformat_close_input(&g_psi.p_format_ctx);
        av_close_input_file(g_psi.p_format_ctx);
        return -1;
    }

    g_psi.audio_stream_index = g_audio_index;
    g_psi.video_stream_index = g_video_index;

    /* get pointers to codex contexts for both streams */
    g_psi.p_audio_codec_ctx = g_psi.p_format_ctx->streams[g_audio_index]->codec;
    g_psi.p_video_codec_ctx = g_psi.p_format_ctx->streams[g_video_index]->codec;

    /* find decoder for audio stream */
    g_psi.p_audio_codec =
        avcodec_find_decoder(g_psi.p_audio_codec_ctx->codec_id);

    if (g_psi.p_audio_codec == NULL)
    {
        printf("ERROR: audio codec not supported\n");
    }

    /* find decoder for video stream */
    g_psi.p_video_codec =
        avcodec_find_decoder(g_psi.p_video_codec_ctx->codec_id);

    if (g_psi.p_video_codec == NULL)
    {
        printf("ERROR: video codec not supported\n");
    }

    /* open decoder for audio stream */
    //if (avcodec_open2(g_psi.p_audio_codec_ctx, g_psi.p_audio_codec,
    //                  NULL) < 0)
    if (avcodec_open(g_psi.p_audio_codec_ctx, g_psi.p_audio_codec) < 0)
    {
        printf("ERROR: could not open audio decoder\n");
        return -1;
    }

    printf("%d\n", g_psi.p_audio_codec_ctx->extradata_size);
    hexdump(g_psi.p_audio_codec_ctx->extradata,
            g_psi.p_audio_codec_ctx->extradata_size);
    printf("%d %d %d %d\n", g_psi.p_audio_codec_ctx->sample_rate,
           g_psi.p_audio_codec_ctx->bit_rate,
           g_psi.p_audio_codec_ctx->channels,
           g_psi.p_audio_codec_ctx->block_align);

    /* open decoder for video stream */
    //if (avcodec_open2(g_psi.p_video_codec_ctx, g_psi.p_video_codec,
    //                  NULL) < 0)
    if (avcodec_open(g_psi.p_video_codec_ctx, g_psi.p_video_codec) < 0)
    {
        printf("ERROR: could not open video decoder\n");
        return -1;
    }

    g_psi.bsfc = av_bitstream_filter_init("h264_mp4toannexb");
    printf("g_psi.bsfc %p\n", g_psi.bsfc);

    if (xrdpvr_set_video_format(channel, 101, 0,
                                g_psi.p_video_codec_ctx->width,
                                g_psi.p_video_codec_ctx->height))
    {
        printf("xrdpvr_set_video_format() failed\n");
        return -1;
    }

    printf("xrdpvr_play_media: calling xrdpvr_set_audio_format\n");
    if (xrdpvr_set_audio_format(channel, 101, 0,
                                g_psi.p_audio_codec_ctx->extradata,
                                g_psi.p_audio_codec_ctx->extradata_size,
                                g_psi.p_audio_codec_ctx->sample_rate,
                                g_psi.p_audio_codec_ctx->bit_rate,
                                g_psi.p_audio_codec_ctx->channels,
                                g_psi.p_audio_codec_ctx->block_align))
    {
        printf("xrdpvr_set_audio_format() failed\n");
        return 1;
    }

    return 0;
}