static void gst_aml_vdec_flush(GstVideoDecoder * dec) { GstAmlVdec *amlvdec = GST_AMLVDEC(dec); GST_WARNING_OBJECT("%s,%d\n", __FUNCTION__,__LINE__); //codec_reset(amlvdec->pcodec); }
static int amlSetPropDecodeHandle(GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec) { GstAmlVdec *amlvdec = GST_AMLVDEC (object); amlvdec->decHandle = g_value_get_pointer (value); return 0; }
static GstFlowReturn gst_aml_vdec_handle_frame(GstVideoDecoder *dec, GstVideoCodecFrame *frame) { GstAmlVdec *amlvdec = GST_AMLVDEC(dec); GstBuffer *outbuffer; GstFlowReturn ret; GstVideoCodecState *state; GST_DEBUG_OBJECT(dec, "%s %d", __FUNCTION__, __LINE__); if (G_UNLIKELY(!frame)) return GST_FLOW_OK; ret = gst_video_decoder_allocate_output_frame(dec, frame); if (G_UNLIKELY(ret != GST_FLOW_OK)) { GST_ERROR_OBJECT(dec, "failed to allocate output frame"); ret = GST_FLOW_ERROR; gst_video_codec_frame_unref(frame); goto done; } gst_aml_vdec_decode(amlvdec, frame->input_buffer); gst_video_decoder_finish_frame(dec, frame); // gst_video_codec_frame_unref(frame); // gst_video_decoder_release_frame(dec, frame); ret = GST_FLOW_OK; done: return ret; }
static int amlGetPropTrickRate(GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec) { GstAmlVdec *amlvdec = GST_AMLVDEC (object); g_value_set_double (value, amlvdec->trickRate); return 0; }
static GstStateChangeReturn gst_aml_vdec_change_state (GstElement * element, GstStateChange transition) { GstStateChangeReturn result = GST_STATE_CHANGE_SUCCESS; gint ret = 0; GstAmlVdec *amlvdec= GST_AMLVDEC (element); GST_ERROR("%s,%d\n",__FUNCTION__,__LINE__); g_return_val_if_fail (GST_IS_AMLVDEC (element), GST_STATE_CHANGE_FAILURE); switch (transition) { case GST_STATE_CHANGE_NULL_TO_READY: GST_ERROR("%s,%d\n",__FUNCTION__,__LINE__); break; case GST_STATE_CHANGE_READY_TO_PAUSED: GST_ERROR("%s,%d\n",__FUNCTION__,__LINE__); break; case GST_STATE_CHANGE_PAUSED_TO_PLAYING: if (amlvdec->is_paused == TRUE && amlvdec->codec_init_ok) { ret=codec_resume (amlvdec->pcodec); if (ret != 0) { GST_ERROR("[%s:%d]resume failed!ret=%d\n", __FUNCTION__, __LINE__, ret); }else amlvdec->is_paused = FALSE; } GST_ERROR("%s,%d\n",__FUNCTION__,__LINE__); break; default: break; } result = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition); switch (transition) { case GST_STATE_CHANGE_PLAYING_TO_PAUSED: GST_ERROR("%s,%d\n",__FUNCTION__,__LINE__); if(!amlvdec->is_eos && amlvdec->codec_init_ok){ ret=codec_pause(amlvdec->pcodec); if (ret != 0) { GST_ERROR("[%s:%d]pause failed!ret=%d\n", __FUNCTION__, __LINE__, ret); }else amlvdec->is_paused = TRUE; } break; case GST_STATE_CHANGE_PAUSED_TO_READY: GST_ERROR("%s,%d\n",__FUNCTION__,__LINE__); break; case GST_STATE_CHANGE_READY_TO_NULL: GST_ERROR("%s,%d\n",__FUNCTION__,__LINE__); break; default: break; } GST_ERROR("%s,%d,ret=%d\n", __FUNCTION__,__LINE__,result); return result; }
static gboolean gst_aml_vdec_stop(GstVideoDecoder * dec) { gboolean ret = FALSE; GstAmlVdec *amlvdec = GST_AMLVDEC(dec); GST_ERROR("%s,%d\n",__FUNCTION__,__LINE__); /* if(amlvdec->codec_init_ok && amlvdec->is_eos ==TRUE) ret=gst_amlvdec_polling_eos(amlvdec); else */ ret = TRUE; return ret; }
static void gst_aml_vdec_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec) { GstAmlVdec *amlvdec = GST_AMLVDEC(object); switch (prop_id) { default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); break; } }
static int amlSetPropTrickRate(GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec) { GstAmlVdec *amlvdec = GST_AMLVDEC (object); gdouble trickRate = g_value_get_double(value); if(amlvdec_forward_process(amlvdec, 0, trickRate, GST_FORMAT_DEFAULT, 0, 0, 0)){ amlvdec->trickRate = trickRate; } return 0; }
static int amlGetPropInterlaced(GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec) { GstAmlVdec *amlvdec = GST_AMLVDEC (object); gboolean interlaced = FALSE; char format[64] = {0}; if(get_sysfs_str("/sys/class/video/frame_format", format, sizeof(format))){ return -1; } if(!strncmp(format, "interlace", strlen("interlace"))){ interlaced = TRUE; } g_value_set_boolean (value, interlaced); return 0; }
static gboolean gst_aml_vdec_open(GstVideoDecoder * dec) { GstAmlVdec *amlvdec = GST_AMLVDEC(dec); amlvdec->pcodec = g_malloc(sizeof(codec_para_t)); memset(amlvdec->pcodec, 0, sizeof(codec_para_t)); #if DEBUG_DUMP amlvdec->dump_fd = open("/data/local/tmp/gst_aml_vdec.dump", O_CREAT | O_TRUNC | O_WRONLY, 0777); if (amlvdec->dump_fd < 0) { GST_ERROR("fd_dump open failed"); } else { codec_set_dump_fd(amlvdec->pcodec, amlvdec->dump_fd); } #endif return TRUE; }
static gboolean gst_aml_vdec_close(GstVideoDecoder * dec) { GstAmlVdec *amlvdec = GST_AMLVDEC(dec); gint ret=0; GST_ERROR("%s,%d\n",__FUNCTION__,__LINE__); stop_eos_task (amlvdec); if (amlvdec->codec_init_ok) { amlvdec->codec_init_ok = 0; if (amlvdec->is_paused == TRUE) { ret = codec_resume(amlvdec->pcodec); if (ret != 0) { GST_ERROR("[%s:%d]resume failed!ret=%d", __FUNCTION__, __LINE__, ret); } else amlvdec->is_paused = FALSE; } set_black_policy(1); codec_close(amlvdec->pcodec); amlvdec->is_headerfeed = FALSE; if (amlvdec->input_state) { gst_video_codec_state_unref(amlvdec->input_state); amlvdec->input_state = NULL; } set_fb0_blank(0); set_fb1_blank(0); //T? set_display_axis(1); } if (amlvdec->info) { amlvdec->info->finalize(amlvdec->info); amlvdec->info = NULL; } #if DEBUG_DUMP if (amlvdec->dump_fd > 0) { codec_set_dump_fd(NULL, 0); close(amlvdec->dump_fd); } #endif if (amlvdec->pcodec) { g_free(amlvdec->pcodec); amlvdec->pcodec = NULL; } return TRUE; }
static gboolean gst_aml_vdec_start(GstVideoDecoder * dec) { GstAmlVdec *amlvdec = GST_AMLVDEC(dec); amlvdec->pcodec->has_video = 1; amlvdec->pcodec->am_sysinfo.rate = 0; amlvdec->pcodec->am_sysinfo.height = 0; amlvdec->pcodec->am_sysinfo.width = 0; amlvdec->pcodec->has_audio = 0; amlvdec->pcodec->noblock = 0; amlvdec->pcodec->stream_type = STREAM_TYPE_ES_VIDEO; amlvdec->is_headerfeed = FALSE; amlvdec->is_paused = FALSE; amlvdec->is_eos = FALSE; amlvdec->codec_init_ok = 0; amlvdec->trickRate = 1.0; return TRUE; }
static gboolean gst_aml_vdec_set_format(GstVideoDecoder *dec, GstVideoCodecState *state) { gboolean ret = FALSE; GstStructure *structure; const char *name; GstVideoInfo *info; gint par_num, par_den; GstVideoFormat fmt; GstAmlVdec *amlvdec = GST_AMLVDEC(dec); g_return_val_if_fail(state != NULL, FALSE); if (amlvdec->input_state) gst_video_codec_state_unref(amlvdec->input_state); amlvdec->input_state = gst_video_codec_state_ref(state); structure = gst_caps_get_structure(state->caps, 0); name = gst_structure_get_name(structure); GST_INFO_OBJECT(amlvdec, "%s = %s", __FUNCTION__, name); if (name) { ret = gst_set_vstream_info(amlvdec, state->caps); if (!amlvdec->output_state) { info = &amlvdec->input_state->info; fmt = GST_VIDEO_FORMAT_xRGB; GST_VIDEO_INFO_WIDTH (info) = amlvdec->pcodec->am_sysinfo.width; GST_VIDEO_INFO_HEIGHT (info) = amlvdec->pcodec->am_sysinfo.height; par_num = GST_VIDEO_INFO_PAR_N(info); par_den = GST_VIDEO_INFO_PAR_D(info); amlvdec->output_state = gst_video_decoder_set_output_state(GST_VIDEO_DECODER(amlvdec), fmt, info->width, info->height, amlvdec->input_state); gst_video_decoder_negotiate (GST_VIDEO_DECODER (amlvdec)); } } return ret; }
static gboolean gst_amlvdec_sink_event (GstVideoDecoder * dec, GstEvent * event) { gboolean ret = TRUE; GstAmlVdec *amlvdec = GST_AMLVDEC(dec); GST_ERROR_OBJECT (amlvdec, "Got %s event on sink pad", GST_EVENT_TYPE_NAME (event)); switch (GST_EVENT_TYPE (event)) { /* case GST_EVENT_NEWSEGMENT: { gboolean update; GstFormat format; gdouble rate, arate; gint64 start, stop, time; stop_eos_task (amlvdec); gst_event_parse_new_segment_full (event, &update, &rate, &arate, &format, &start, &stop, &time); if (format != GST_FORMAT_TIME) goto newseg_wrong_format; amlvdec_forward_process(amlvdec, update, rate, format, start, stop, time); gst_segment_set_newsegment_full (&amlvdec->segment, update, rate, arate, format, start, stop, time); GST_DEBUG_OBJECT (amlvdec,"Pushing newseg rate %g, applied rate %g, format %d, start %" G_GINT64_FORMAT ", stop %" G_GINT64_FORMAT ", pos %" G_GINT64_FORMAT, rate, arate, format, start, stop, time); ret = gst_pad_push_event (amlvdec->srcpad, event); break; }*/ case GST_EVENT_FLUSH_START: if(amlvdec->codec_init_ok){ set_black_policy(0); } ret = TRUE; break; case GST_EVENT_FLUSH_STOP: { stop_eos_task (amlvdec); if(amlvdec->codec_init_ok){ gint res = -1; res = codec_reset(amlvdec->pcodec); if (res < 0) { GST_ERROR("reset vcodec failed, res= %x\n", res); return FALSE; } amlvdec->is_headerfeed = FALSE; } GST_WARNING("vformat:%d\n", amlvdec->pcodec->video_type); break; } case GST_EVENT_EOS: GST_WARNING("get GST_EVENT_EOS,check for video end\n"); if(amlvdec->codec_init_ok) { start_eos_task(amlvdec); amlvdec->is_eos = TRUE; } ret = TRUE; break; default: break; } done: ret = GST_VIDEO_DECODER_CLASS (parent_class)->sink_event (amlvdec, event); return ret; }