int main() { dt_get_log_level(); dt_info("TEST", "this is info level test \n"); dt_error("TEST", "this is error level test \n"); dt_debug("TEST", "this is debug level test \n"); dt_warning("TEST", "this is warnning level test \n"); dt_set_log_level(1); dt_info("TEST", "this is info level test \n"); dt_error("TEST", "this is error level test \n"); dt_debug("TEST", "this is debug level test \n"); dt_warning("TEST", "this is warning level test \n"); return; }
static int demuxer_ffmpeg_read_frame (demuxer_wrapper_t * wrapper, dt_av_frame_t * frame) { dtdemuxer_context_t *dem_ctx = (dtdemuxer_context_t *) wrapper->parent; dt_media_info_t *media_info = &dem_ctx->media_info; int has_audio = (media_info->no_audio) ? 0 : media_info->has_audio; int has_video = (media_info->no_video) ? 0 : media_info->has_video; int has_sub = (media_info->no_sub) ? 0 : media_info->has_sub; int cur_aidx = (has_audio) ? media_info->astreams[media_info->cur_ast_index]->index : -1; int cur_vidx = (has_video) ? media_info->vstreams[media_info->cur_vst_index]->index : -1; int cur_sidx = (has_sub) ? media_info->sstreams[media_info->cur_sst_index]->index : -1; AVFormatContext *ic = (AVFormatContext *) wrapper->demuxer_priv; AVPacket avpkt; int ret = av_read_frame (ic, &avpkt); if (ret < 0) { if (AVERROR (EAGAIN) != ret) { /*if the return is EAGAIN,we need to try more times */ dt_warning (TAG, "[%s:%d]av_read_frame return (%d)\n", __FUNCTION__, __LINE__, ret); if (AVERROR_EOF != ret) return DTERROR_READ_FAILED; else return DTERROR_READ_EOF; } return DTERROR_READ_AGAIN; } //read frame ok if (has_video && cur_vidx == avpkt.stream_index) frame->type = AVMEDIA_TYPE_VIDEO; else if (has_audio && cur_aidx == avpkt.stream_index) frame->type = AVMEDIA_TYPE_AUDIO; else if (has_sub && cur_sidx == avpkt.stream_index) frame->type = AVMEDIA_TYPE_SUBTITLE; else { frame->type = AVMEDIA_TYPE_UNKNOWN; av_free_packet (&avpkt); return DTERROR_READ_AGAIN; // need to read again } //setup frame frame->data = avpkt.data; frame->size = avpkt.size; frame->pts = pts_exchange (&avpkt, media_info); frame->dts = avpkt.dts; frame->duration = avpkt.duration; dt_debug (TAG, "read ok,frame size:%d %02x %02x %02x %02x addr:%p\n", frame->size, frame->data[0], frame->data[1], frame->data[2], frame->data[3], frame->data); dt_debug (TAG, "SIDE_DATA_ELEMENT:%d \n", avpkt.side_data_elems); return DTERROR_NONE; }
int dt_remove_server (event_server_t * server) { dt_server_mgt_t *mgt = &server_mgt; int count = server->event_count; dt_info (TAG, "REMOVE %s \n", server->name); /*remove all events */ if (count == 0) goto REMOVE_SERVICE; event_t *event = server->event; event_t *event_next = event->next; while (event) { free (event); server->event_count--; event = event_next; if (event) event_next = event->next; } REMOVE_SERVICE: if (server->id == EVENT_SERVER_MAIN) return 0; event_server_t *entry = mgt->server; while (entry->next && entry->next->id != server->id) entry = entry->next; if (entry->next && entry->next->id == server->id) { entry->next = entry->next->next; mgt->server_count--; } if (server->event_count > 0) dt_warning (TAG, "EVENT COUNT !=0 AFTER REMOVE \n"); if (server->id != EVENT_SERVER_MAIN) free (server); return 0; }
static int demuxer_ffmpeg_setup_info (demuxer_wrapper_t * wrapper, dt_media_info_t * info) { AVFormatContext *ic = (AVFormatContext *) wrapper->demuxer_priv; AVStream *pStream; AVCodecContext *pCodec; vstream_info_t *vst_info; astream_info_t *ast_info; sstream_info_t *sst_info; int i; /*reset vars */ memset (info, 0, sizeof (*info)); //set cur stream index -1 ,other vars have been reset to 0 info->cur_ast_index = -1; info->cur_vst_index = -1; info->cur_sst_index = -1; /*get media info */ info->format = MEDIA_FORMAT_INVALID; info->bit_rate = ic->bit_rate; double duration = ((double) ic->duration / AV_TIME_BASE); info->duration = (int) (ic->duration / AV_TIME_BASE); strcpy (info->file_name, ic->filename); dt_info (TAG, "file name:%s duration:%lf\n", info->file_name, duration); info->file_size = avio_size (ic->pb); info->format = media_format_convert (ic->iformat->name); if (info->format == MEDIA_FORMAT_INVALID) dt_warning (TAG, "get wrong media format\n"); //get stream info for (i = 0; i < ic->nb_streams; i++) { pStream = ic->streams[i]; pCodec = pStream->codec; if (pCodec->codec_type == AVMEDIA_TYPE_VIDEO) { vst_info = (vstream_info_t *) malloc (sizeof (vstream_info_t)); memset (vst_info, 0, sizeof (vstream_info_t)); vst_info->index = pStream->index; vst_info->id = pStream->id; vst_info->width = pCodec->width; vst_info->height = pCodec->height; vst_info->pix_fmt = pCodec->pix_fmt; vst_info->duration = (int64_t) (pStream->duration * pStream->time_base.num / pStream->time_base.den); vst_info->bit_rate = pCodec->bit_rate; vst_info->format = video_format_convert (pCodec->codec_id); vst_info->sample_aspect_ratio.num = pStream->sample_aspect_ratio.num; vst_info->sample_aspect_ratio.den = pStream->sample_aspect_ratio.den; vst_info->frame_rate_ratio.num = pStream->r_frame_rate.num; vst_info->frame_rate_ratio.den = pStream->r_frame_rate.den; vst_info->time_base.num = pStream->time_base.num; vst_info->time_base.den = pStream->time_base.den; vst_info->codec_priv = (void *) pCodec; info->vstreams[info->vst_num] = vst_info; info->vst_num++; } else if (pCodec->codec_type == AVMEDIA_TYPE_AUDIO) { ast_info = (astream_info_t *) malloc (sizeof (astream_info_t)); memset (ast_info, 0, sizeof (astream_info_t)); ast_info->index = pStream->index; ast_info->id = pStream->id; ast_info->channels = pCodec->channels; ast_info->sample_rate = pCodec->sample_rate; ast_info->bps = format2bps (pCodec->sample_fmt); ast_info->duration = (int64_t) (pStream->duration * pStream->time_base.num / pStream->time_base.den); ast_info->time_base.num = pStream->time_base.num; ast_info->time_base.den = pStream->time_base.den; ast_info->bit_rate = pCodec->bit_rate; ast_info->format = audio_format_convert (pCodec->codec_id); ast_info->codec_priv = (void *) pCodec; info->astreams[info->ast_num] = ast_info; info->ast_num++; } else if (pCodec->codec_type == AVMEDIA_TYPE_SUBTITLE) { sst_info = (sstream_info_t *) malloc (sizeof (sstream_info_t)); memset (sst_info, 0, sizeof (sstream_info_t)); sst_info->index = pStream->index; sst_info->id = pStream->id; sst_info->width = pCodec->width; sst_info->height = pCodec->height; sst_info->format = subtitle_format_convert (pCodec->codec_id); sst_info->codec_priv = (void *) pCodec; info->sstreams[info->sst_num] = sst_info; info->sst_num++; } } if (info->vst_num > 0) { info->has_video = 1; info->cur_vst_index = 0; } if (info->ast_num > 0) { info->has_audio = 1; info->cur_ast_index = 0; } if (info->sst_num > 0) { info->has_sub = 1; info->cur_sst_index = 0; } return 0; }