コード例 #1
0
/* --------------------------------------------------------------------------*/
int player_start(play_control_t *ctrl_p, unsigned long  priv)
{
    int ret;
    int pid = -1;
    play_para_t *p_para;
    //char stb_source[32];

    update_loglevel_setting();
    print_version_info();
    log_print("[player_start:enter]p=%p black=%d\n", ctrl_p, get_black_policy());

    if (ctrl_p == NULL) {
        return PLAYER_EMPTY_P;
    }

    /*keep last frame displaying --default*/
    set_black_policy(0);
    /* if not set keep last frame, or change file playback, clear display last frame */
    if (!ctrl_p->displast_frame) {
        set_black_policy(1);
    } else if (!check_file_same(ctrl_p->file_name)) {
        set_black_policy(1);
    }

    pid = player_request_pid();
    if (pid < 0) {
        return PLAYER_NOT_VALID_PID;
    }

    p_para = MALLOC(sizeof(play_para_t));
    if (p_para == NULL) {
        return PLAYER_NOMEM;
    }

    MEMSET(p_para, 0, sizeof(play_para_t));

    /* init time_point to a invalid value */
    p_para->playctrl_info.time_point = -1;

    player_init_pid_data(pid, p_para);

    message_pool_init(p_para);

    p_para->start_param = ctrl_p;
    p_para->player_id = pid;
    p_para->extern_priv = priv;
    log_debug1("[player_start]player_para=%p,start_param=%p pid=%d\n", p_para, p_para->start_param, pid);

    ret = player_thread_create(p_para) ;
    if (ret != PLAYER_SUCCESS) {
        FREE(p_para);
        player_release_pid(pid);
        return PLAYER_CAN_NOT_CREAT_THREADS;
    }
    log_print("[player_start:exit]pid = %d \n", pid);

    return pid;
}
コード例 #2
0
int player_init(void)
{
    print_version_info();
    update_loglevel_setting();
    /*register all formats and codecs*/
    ffmpeg_init();

    player_id_pool_init();

    codec_audio_basic_init();

    /*register all support decoder */
    ts_register_stream_decoder();
    es_register_stream_decoder();
    ps_register_stream_decoder();
    rm_register_stream_decoder();
    audio_register_stream_decoder();
    video_register_stream_decoder();

    return PLAYER_SUCCESS;
}
コード例 #3
0
int thumbnail_decoder_open(void *handle, const char* filename)
{
    int i;
    int video_index = -1;
    struct video_frame *frame = (struct video_frame *)handle;
    struct stream *stream = &frame->stream;

    log_debug("thumbnail open file:%s\n", filename);
	update_loglevel_setting();
    if (av_open_input_file(&stream->pFormatCtx, filename, NULL, 0, NULL) != 0) {
        log_print("Coundn't open file %s !\n", filename);
        goto err;
    }

    //thumbnail extract frame, so need fast_switch
    stream->pFormatCtx->pb->local_playback = 1;

    if (av_find_stream_info(stream->pFormatCtx) < 0) {
        log_print("Coundn't find stream information !\n");
        goto err1;
    }

    //dump_format(stream->pFormatCtx, 0, filename, 0);
    for (i = 0; i < stream->pFormatCtx->nb_streams; i++) {
        if (stream->pFormatCtx->streams[i]->codec->codec_type == CODEC_TYPE_VIDEO) {
            video_index = i;
            break;
        }
    }

    if (video_index == -1) {
        log_print("Didn't find a video stream!\n");
        goto err1;
    }

    find_thumbnail_frame(stream->pFormatCtx, video_index, &frame->thumbNailTime, &frame->thumbNailOffset,&frame->maxframesize);

    stream->videoStream = video_index;
    stream->pCodecCtx = stream->pFormatCtx->streams[video_index]->codec;
    if (stream->pCodecCtx == NULL) {
        log_print("pCodecCtx is NULL !\n");
    }

    frame->width = stream->pCodecCtx->width;
    frame->height = stream->pCodecCtx->height;

    stream->pCodec = avcodec_find_decoder(stream->pCodecCtx->codec_id);
    if (stream->pCodec == NULL) {
        log_print("Didn't find codec!\n");
        goto err1;
    }

    if (avcodec_open(stream->pCodecCtx, stream->pCodec) < 0) {
        log_print("Couldn't open codec!\n");
        goto err1;
    }

    frame->duration = stream->pFormatCtx->duration;

    stream->pFrameYUV = avcodec_alloc_frame();
    if (stream->pFrameYUV == NULL) {
        log_print("alloc YUV frame failed!\n");
        goto err2;
    }

    stream->pFrameRGB = avcodec_alloc_frame();
    if (stream->pFrameRGB == NULL) {
        log_print("alloc RGB frame failed!\n");
        goto err3;
    }

    frame->DataSize = avpicture_get_size(DEST_FMT, frame->width, frame->height);
    frame->data = (char *)malloc(frame->DataSize);
    if (frame->data == NULL) {
        log_print("alloc buffer failed!\n");
        goto err4;
    }

    avpicture_fill((AVPicture *)stream->pFrameRGB, frame->data, DEST_FMT, frame->width, frame->height);

    return 0;

err4:
    av_free(stream->pFrameRGB);
err3:
    av_free(stream->pFrameYUV);
err2:
    avcodec_close(stream->pCodecCtx);
err1:
    av_close_input_file(stream->pFormatCtx);
err:
    memset(&frame->stream, 0, sizeof(struct stream));

    return -1;
}