⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 playback.c

📁 本程序使用gstreamer实现音视频播放,。
💻 C
📖 第 1 页 / 共 3 页
字号:
  loop = g_main_loop_new(NULL, TRUE);  g_main_loop_run(loop);  printf("----------play over---------\n");  if(media.g_pipe)  {     gst_element_set_state (media.g_pipe, GST_STATE_NULL);     gst_object_unref (GST_OBJECT (media.g_pipe));    }#endif  return 0;}//////////////////////////////////////////////////////////////////////////////////////for debug gstreamer function. for the normal operator, you should shut off it.#ifdef DEBUG_GSTgint main (gint argc, gchar *argv[]){  printf("	++++ %s ++++\n", __func__);  start_gstreamer(argv[1]);  return 0;}#endif////////////////////////////////////////////////////////////////////////////////////////////forward and backward/////////////////////////////////////////////////////descriptor: get stream length.//para://return value://////////////////////////////////////////////////gint64 get_stream_length(){  printf("	++++ %s ++++\n", __func__);  if(media.stream_length == 0 && media.g_pipe != NULL)  {    GstFormat fmt = GST_FORMAT_TIME;    gint64 len=-1;    if(gst_element_query_duration(media.g_pipe, &fmt, &len) && len != -1)    {      media.stream_length = len / GST_MSECOND;    }  }  return media.stream_length;}/////////////////////////////////////////////////////descriptor: got current time.//para://return value://////////////////////////////////////////////////static void got_time_tick(GstElement *play, gint64 set_time){  printf("	++++ %s ++++\n", __func__);  media.cur_time = (gint64)set_time/GST_MSECOND;  g_print("current time is: %ld\n", media.cur_time);  /*if(media.stream_length == 0)  {    media.cur_position = 0;  }  else  {    media.cur_position = media.cur_time/media.stream_length;  }*/}/////////////////////////////////////////////////////descriptor: get current time.//para://return value://////////////////////////////////////////////////void get_current_time()	{  printf("	++++ %s ++++\n", __func__);  GstFormat fmt = GST_FORMAT_TIME;  gint64 prev_len=-1;  gint64 pos=-1, len=-1;  if(media.stream_length == 0)    media.stream_length = get_stream_length(media.g_pipe);  prev_len = media.stream_length;  g_print("stream length is: %ld\n", prev_len);  if(gst_element_query_duration(media.g_pipe, &fmt, &len))  {    if(len != -1 && fmt == GST_FORMAT_TIME)    {      //g_print("gst msecond is: %d\n", GST_MSECOND);  //GST_MSECOND=1000000      media.stream_length = len / GST_MSECOND;      if(media.stream_length  != prev_len)      {        g_print("stream_length is error. \n");      }    }  }  else  {    g_print("could not get duration\n");  }  if(gst_element_query_position(media.g_pipe, &fmt, &pos))  {    if(pos != -1 && fmt == GST_FORMAT_TIME)    {      got_time_tick(GST_ELEMENT(media.g_pipe),pos);    }  }  else  {    g_print("could not get position.\n");  }  //return TRUE;}/////////////////////////////////////////////////////descriptor: seek to a position by time.//para://return value://////////////////////////////////////////////////gboolean video_local_seek_time(gint64 time, GError **gerror){  printf("	++++ %s ++++\n", __func__);  gst_element_seek(media.g_pipe, 1.0, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH |    				GST_SEEK_FLAG_KEY_UNIT, GST_SEEK_TYPE_SET,    				time*GST_MSECOND, GST_SEEK_TYPE_NONE,     				GST_CLOCK_TIME_NONE);  gst_element_get_state(media.g_pipe, NULL, NULL, 100*GST_MSECOND);  //return TRUE;}/////////////////////////////////////////////////////descriptor: seek to a specify position.//para://return value://////////////////////////////////////////////////void seek_to_a_position(int offset_second){  GError *err = NULL;  gint64 off_msec, oldsec, sec;  printf("	++++ %s ++++\n", __func__);  off_msec = offset_second * 1000;  get_current_time(media.g_pipe);  oldsec = media.cur_time;  sec = MAX(0, oldsec + off_msec);  video_local_seek_time(sec, &err);}/////////////////////////////////////////////////////descriptor: forward.//para://return value://////////////////////////////////////////////////void forward_to_next_position(){  seek_to_a_position(FORWARD_OFFSET);  }/////////////////////////////////////////////////////descriptor:previous //para://return value://////////////////////////////////////////////////void backward_to_previous_position(){  seek_to_a_position(BACKWARD_OFFSET);}#ifdef DEBUG_GST/////////////////////////////////////////////////////descriptor: for debug.//para://return value://////////////////////////////////////////////////static gboolean check_other_function(gchar *filename){  printf("	++++ %s() ++++ file= %s.\n", __func__, filename);  #ifdef GET_CAPS //get caps.  g_print("****it will get caps****\n");  getCaps(filename);  printf("over.......................\n");#endif	#ifdef SET_VIDEO_PARA  //set video para.    g_print("****it will set video para****\n");  set_video_brightness(10000);  set_video_contrast(20000);  set_video_saturation(30000);  set_video_hue(40000);#endif#ifdef PLAY_STATE  g_print("****it will play/stop/pause****\n");  //pause.    pause_playback();  //play  //start_playback();  //stop  //stop_playback();#endif#ifdef FORWARD_BACKWARD  //is forward and backward  //GstFormat fmt;  //gint64 val;  //gint dir=1;  g_print("****it will forward or backward****\n");  gst_element_set_state(media.g_pipe, GST_STATE_PAUSED);  forward_to_next_position();  //backward_to_previous_position();  gst_element_set_state(media.g_pipe, GST_STATE_PLAYING);#endif#ifdef GST_VOLUME  g_print("****it will adjust volume.****\n");  adjust_volume_add();  //adjust_volume_sub();  #endif}#endif//////////////////////////////////////////////////////////////////////////////////////get video para./////////////////////////////////////////////////////descriptor: get video property.//para://return value://////////////////////////////////////////////////int video_local_get_video_property (LocalVideoProperty type){  int ret;  printf("	++++ %s ++++\n", __func__);  //g_return_val_if_fail ( != NULL, 65535/2);  //g_return_val_if_fail (BACON_IS_VIDEO_LOCAL (), 65535/2);    g_mutex_lock (media.lock);  if (media.balance && GST_IS_COLOR_BALANCE (media.balance))  {      //g_print("2222222222222\n");      const GList *channels_list = NULL;      GstColorBalanceChannel *found_channel = NULL;            channels_list = gst_color_balance_list_channels (media.balance);          while (channels_list != NULL && found_channel == NULL)      { /* We search for the right channel corresponding to type */          GstColorBalanceChannel *channel = channels_list->data;          if (type == VIDEO_BRIGHTNESS && channel &&		  	g_strrstr (channel->label, "BRIGHTNESS"))          {              g_object_ref (channel);              found_channel = channel;          }          else if (type == VIDEO_CONTRAST && channel &&		  	g_strrstr (channel->label, "CONTRAST"))          {              g_object_ref (channel);              found_channel = channel;          }          else if (type == VIDEO_SATURATION && channel &&		  	g_strrstr (channel->label, "SATURATION"))          {              g_object_ref (channel);              found_channel = channel;          }          else if (type == VIDEO_HUE && channel && 		  	g_strrstr (channel->label, "HUE"))          {              g_object_ref (channel);              found_channel = channel;          }          channels_list = g_list_next (channels_list);      }              if (found_channel && GST_IS_COLOR_BALANCE_CHANNEL (found_channel))       {        gint cur;        cur = gst_color_balance_get_value (media.balance, found_channel);        GST_DEBUG ("channel %s: cur=%d, min=%d, max=%d", found_channel->label,            cur, found_channel->min_value, found_channel->max_value);        ret = ((double) cur - found_channel->min_value) * 65535 /              ((double) found_channel->max_value - found_channel->min_value);        GST_DEBUG ("channel %s: returning value %d", found_channel->label, ret);        g_object_unref (found_channel);        goto done;      }  }  /* value wasn't found, get from gconf */  //ret = gconf_client_get_int (>media->gc, video_props_str[type], NULL);  //GST_DEBUG ("nothing found for type %d, returning value %d from gconf key %s",  //    type, ret, video_props_str[type]);done:  g_mutex_unlock (media.lock);  return ret;}/////////////////////////////////////////////////////descriptor: set video property.//para://return value://////////////////////////////////////////////////void video_local_set_video_property (LocalVideoProperty type, int value){  //g_return_if_fail (!= NULL);  //g_return_if_fail (BACON_IS_VIDEO_WIDGET ());  printf("	++++ %s ++++\n", __func__);  GST_DEBUG ("set video property type %d to value %d", type, value);    if ( !(value < 65535 && value > 0) )    return;  if (media.balance && GST_IS_COLOR_BALANCE (media.balance))  {      const GList *channels_list = NULL;      GstColorBalanceChannel *found_channel = NULL;            channels_list = gst_color_balance_list_channels (media.balance);      while (found_channel == NULL && channels_list != NULL)       {          /* We search for the right channel corresponding to type */          GstColorBalanceChannel *channel = channels_list->data;          if (type == VIDEO_BRIGHTNESS && channel &&              g_strrstr (channel->label, "BRIGHTNESS"))          {              g_object_ref (channel);              found_channel = channel;          }          else if (type == VIDEO_CONTRAST && channel &&              g_strrstr (channel->label, "CONTRAST"))          {              g_object_ref (channel);              found_channel = channel;          }          else if (type == VIDEO_SATURATION && channel &&              g_strrstr (channel->label, "SATURATION"))          {              g_object_ref (channel);              found_channel = channel;          }          else if (type == VIDEO_HUE && channel &&              g_strrstr (channel->label, "HUE"))          {              g_object_ref (channel);              found_channel = channel;          }          channels_list = g_list_next (channels_list);      }      if (found_channel && GST_IS_COLOR_BALANCE_CHANNEL (found_channel))      {          int i_value = value * ((double) found_channel->max_value -              found_channel->min_value) / 65535 + found_channel->min_value;          GST_DEBUG ("channel %s: set to %d/65535", found_channel->label, value);          gst_color_balance_set_value (media.balance, found_channel,                                       i_value);          GST_DEBUG ("channel %s: val=%d, min=%d, max=%d", found_channel->label,              i_value, found_channel->min_value, found_channel->max_value);          g_object_unref (found_channel);      }  }  /* save in gconf */  //gconf_client_set_int (>media->gc, video_props_str[type], value, NULL);  //GST_DEBUG ("setting value %d on gconf key %s", value, video_props_str[type]);}/////////////////////////////////////////////////////descriptor: set brighness for video.//para://return value://////////////////////////////////////////////////void set_video_brightness(int value){  printf("	++++ %s ++++\n", __func__);   video_local_get_video_property (VIDEO_BRIGHTNESS);  video_local_set_video_property (VIDEO_BRIGHTNESS, value);}/////////////////////////////////////////////////////descriptor: set contrast  video.//para://return value://////////////////////////////////////////////////void set_video_contrast(int value){  video_local_get_video_property (VIDEO_CONTRAST);  video_local_set_video_property (VIDEO_CONTRAST,value);}/////////////////////////////////////////////////////descriptor: set saturation for video.//para://return value:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -