e821e1e30818d24595017565641381f8e99d9169
[platform/core/multimedia/libmm-player.git] / src / mm_player_es.c
1 /*
2  * libmm-player
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: JongHyuk Choi <jhchoi.choi@samsung.com>, heechul jeon <heechul.jeon@samsung.co>,
7  * YoungHwan An <younghwan_.an@samsung.com>, Eunhae Choi <eunhae1.choi@samsung.com>
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  */
22
23 /*===========================================================================================
24 |                                                                                                                                                                                       |
25 |  INCLUDE FILES                                                                                                                                                        |
26 |                                                                                                                                                                                       |
27 ========================================================================================== */
28 #include <dlog.h>
29 #include "mm_player_es.h"
30 #include "mm_player_utils.h"
31 #include "mm_player_internal.h"
32
33 #include <gst/app/gstappsrc.h>
34
35 /*---------------------------------------------------------------------------
36 |    LOCAL VARIABLE DEFINITIONS for internal                                                            |
37 ---------------------------------------------------------------------------*/
38
39 /*---------------------------------------------------------------------------
40 |    LOCAL FUNCTION PROTOTYPES:                                                                                         |
41 ---------------------------------------------------------------------------*/
42 static int _parse_media_format (MMPlayerVideoStreamInfo * video, MMPlayerAudioStreamInfo * audio, media_format_h format);
43 static int _convert_media_format_video_mime_to_str (MMPlayerVideoStreamInfo * video, media_format_mimetype_e mime);
44 static int _convert_media_format_audio_mime_to_str (MMPlayerAudioStreamInfo * audio, media_format_mimetype_e mime);
45
46 /*===========================================================================================
47 |                                                                                                                                                                                       |
48 |  FUNCTION DEFINITIONS                                                                                                                                         |
49 |                                                                                                                                                                                       |
50 ========================================================================================== */
51
52 static int
53 _convert_media_format_video_mime_to_str (MMPlayerVideoStreamInfo * video,
54     media_format_mimetype_e mime)
55 {
56   MMPLAYER_RETURN_VAL_IF_FAIL (video, MM_ERROR_INVALID_ARGUMENT);
57
58   switch (mime) {
59     case MEDIA_FORMAT_MPEG4_SP:
60       video->mime = g_strdup ("video/mpeg");
61       video->version = 4;
62       break;
63     case MEDIA_FORMAT_H264_SP:
64         case MEDIA_FORMAT_H264_MP:
65         case MEDIA_FORMAT_H264_HP:
66       video->mime = g_strdup ("video/x-h264");
67       break;
68     default:
69       video->mime = g_strdup ("unknown");
70       break;
71   }
72
73   return MM_ERROR_NONE;
74 }
75
76 static int
77 _convert_media_format_audio_mime_to_str (MMPlayerAudioStreamInfo * audio,
78     media_format_mimetype_e mime)
79 {
80   MMPLAYER_RETURN_VAL_IF_FAIL (audio, MM_ERROR_INVALID_ARGUMENT);
81
82   switch (mime) {
83     case MEDIA_FORMAT_AAC:
84       audio->mime = g_strdup ("audio/mpeg");
85       audio->version = 2;
86       break;
87     default:
88       audio->mime = g_strdup ("unknown");
89       break;
90   }
91
92   return MM_ERROR_NONE;
93 }
94
95 static int
96 _parse_media_format (MMPlayerVideoStreamInfo * video,
97     MMPlayerAudioStreamInfo * audio, media_format_h format)
98 {
99   if (audio) {
100     media_format_mimetype_e mime;
101     int channel;
102     int samplerate;
103     int avg_bps;
104
105     if (media_format_get_audio_info (format, &mime, &channel, &samplerate, NULL,
106             &avg_bps) != MEDIA_FORMAT_ERROR_NONE) {
107       LOGE ("media_format_get_audio_info failed");
108           return MM_ERROR_PLAYER_INTERNAL;
109     }
110
111     _convert_media_format_audio_mime_to_str (audio, mime);
112     audio->sample_rate = samplerate;
113     audio->channels = channel;
114 //video->user_info = ;
115   }
116
117   if (video) {
118     media_format_mimetype_e mime;
119     int width;
120     int height;
121     int avg_bps;
122
123     if (media_format_get_video_info (format, &mime, &width, &height, &avg_bps,
124             NULL) != MEDIA_FORMAT_ERROR_NONE) {
125       LOGE ("media_format_get_video_info failed");
126           return MM_ERROR_PLAYER_INTERNAL;
127     }
128
129     _convert_media_format_video_mime_to_str (video, mime);
130     video->width = width;
131     video->height = height;
132   }
133
134   return MM_ERROR_NONE;
135 }
136
137 static gboolean
138 _mmplayer_update_video_info(MMHandleType hplayer, media_format_h fmt)
139 {
140   mm_player_t *player = (mm_player_t *) hplayer;
141   gboolean ret = FALSE;
142   GstStructure *str = NULL;
143   media_format_mimetype_e mimetype = 0;
144   gint cur_width = 0, width = 0;
145   gint cur_height = 0, height = 0;
146
147   MMPLAYER_FENTER ();
148
149   MMPLAYER_RETURN_VAL_IF_FAIL (player, FALSE);
150   MMPLAYER_RETURN_VAL_IF_FAIL (fmt, FALSE);
151
152   if (player->v_stream_caps)
153   {
154     str = gst_caps_get_structure (player->v_stream_caps, 0);
155     if ( !gst_structure_get_int (str, "width", &cur_width))
156     {
157       LOGD ("missing 'width' field in video caps");
158     }
159
160     if ( !gst_structure_get_int (str, "height", &cur_height))
161     {
162       LOGD ("missing 'height' field in video caps");
163     }
164
165     media_format_get_video_info(fmt, &mimetype, &width, &height, NULL, NULL);
166     if ((cur_width != width) || (cur_height != height))
167     {
168       LOGW ("resolution is changed %dx%d -> %dx%d",
169                           cur_width, cur_height, width, height);
170       _mmplayer_set_video_info(hplayer, fmt);
171       ret = TRUE;
172     }
173   }
174
175   MMPLAYER_FLEAVE ();
176   return ret;
177 }
178
179
180 int
181 _mmplayer_set_media_stream_buffer_status_cb(MMHandleType hplayer,
182                                             MMPlayerStreamType type,
183                                             mm_player_media_stream_buffer_status_callback callback,
184                                             void *user_param)
185 {
186         mm_player_t *player = (mm_player_t *) hplayer;
187
188         MMPLAYER_FENTER ();
189
190         MMPLAYER_RETURN_VAL_IF_FAIL (player, MM_ERROR_PLAYER_NOT_INITIALIZED);
191
192         if ((type < MM_PLAYER_STREAM_TYPE_DEFAULT) || (type > MM_PLAYER_STREAM_TYPE_TEXT))
193                 return MM_ERROR_INVALID_ARGUMENT;
194
195         if (player->media_stream_buffer_status_cb[type])
196         {
197                 if (!callback)
198                 {
199                         LOGD ("[type:%d] will be clear.\n", type);
200                 }
201                 else
202                 {
203                         LOGD ("[type:%d] will be overwritten.\n", type);
204                 }
205         }
206
207         player->media_stream_buffer_status_cb[type] = callback;
208         player->buffer_cb_user_param = user_param;
209
210         LOGD ("player handle %p, type %d, callback %p\n", player, type,
211                 player->media_stream_buffer_status_cb[type]);
212
213         MMPLAYER_FLEAVE ();
214
215         return MM_ERROR_NONE;
216 }
217
218 int
219 _mmplayer_set_media_stream_seek_data_cb(MMHandleType hplayer,
220                                         MMPlayerStreamType type,
221                                         mm_player_media_stream_seek_data_callback callback,
222                                         void *user_param)
223 {
224         mm_player_t *player = (mm_player_t *) hplayer;
225
226         MMPLAYER_FENTER ();
227
228         MMPLAYER_RETURN_VAL_IF_FAIL (player, MM_ERROR_PLAYER_NOT_INITIALIZED);
229
230         if ((type < MM_PLAYER_STREAM_TYPE_DEFAULT) || (type > MM_PLAYER_STREAM_TYPE_TEXT))
231                 return MM_ERROR_INVALID_ARGUMENT;
232
233         if (player->media_stream_seek_data_cb[type])
234         {
235                 if (!callback)
236                 {
237                         LOGD ("[type:%d] will be clear.\n", type);
238                 }
239                 else
240                 {
241                         LOGD ("[type:%d] will be overwritten.\n", type);
242                 }
243         }
244
245         player->media_stream_seek_data_cb[type] = callback;
246         player->buffer_cb_user_param = user_param;
247
248         LOGD ("player handle %p, type %d, callback %p\n", player, type,
249                 player->media_stream_seek_data_cb[type]);
250
251         MMPLAYER_FLEAVE ();
252
253         return MM_ERROR_NONE;
254 }
255
256 GstElement*
257 __mmplayer_get_source_element (mm_player_t *player, MMPlayerStreamType type)
258 {
259         enum MainElementID elemId = MMPLAYER_M_NUM;
260
261         if (player && player->pipeline && player->pipeline->mainbin) {
262
263                 /* get elem according to the stream type */
264                 if (type == MM_PLAYER_STREAM_TYPE_AUDIO) {
265                         if (player->pipeline->mainbin[MMPLAYER_M_2ND_SRC].gst) {
266                                 elemId = MMPLAYER_M_2ND_SRC;
267                         } else if (g_strrstr (GST_ELEMENT_NAME (player->pipeline->mainbin[MMPLAYER_M_SRC].gst), "audio_appsrc")) {
268                                 elemId = MMPLAYER_M_SRC;
269                         }
270                 }
271                 else if (type == MM_PLAYER_STREAM_TYPE_VIDEO) {
272                         elemId = MMPLAYER_M_SRC;
273                 }
274                 else if (type == MM_PLAYER_STREAM_TYPE_TEXT) {
275                         elemId = MMPLAYER_M_SUBSRC;
276                 }
277
278                 if (elemId != MMPLAYER_M_NUM)
279                         return player->pipeline->mainbin[elemId].gst;
280         }
281
282         return NULL;
283 }
284
285 int
286 _mmplayer_set_media_stream_max_size(MMHandleType hplayer, MMPlayerStreamType type, guint64 max_size)
287 {
288         mm_player_t *player = (mm_player_t *) hplayer;
289         GstElement *element = NULL;
290
291         MMPLAYER_FENTER ();
292         MMPLAYER_RETURN_VAL_IF_FAIL (player, MM_ERROR_PLAYER_NOT_INITIALIZED);
293
294         if ((type < MM_PLAYER_STREAM_TYPE_AUDIO) ||
295                 (type > MM_PLAYER_STREAM_TYPE_TEXT) ||
296                 (max_size == 0)) {
297                 LOGE ("Invalid param type:%d, max_size:%d", type, max_size);
298                 return MM_ERROR_INVALID_ARGUMENT;
299         }
300
301         LOGD ("type %d, max_size %llu\n", type, max_size);
302
303         if ((element = __mmplayer_get_source_element(player, type))) {
304                 LOGD ("update max_size of %s\n", GST_ELEMENT_NAME(element));
305                 g_object_set(G_OBJECT(element), "max-bytes", max_size, NULL);
306         }
307
308         player->media_stream_buffer_max_size[type] = max_size;
309
310         MMPLAYER_FLEAVE ();
311         return MM_ERROR_NONE;
312 }
313
314 int
315 _mmplayer_get_media_stream_max_size(MMHandleType hplayer, MMPlayerStreamType type, guint64 *max_size)
316 {
317         mm_player_t *player = (mm_player_t *) hplayer;
318
319         MMPLAYER_FENTER ();
320
321         MMPLAYER_RETURN_VAL_IF_FAIL (player, MM_ERROR_PLAYER_NOT_INITIALIZED);
322         MMPLAYER_RETURN_VAL_IF_FAIL (max_size, MM_ERROR_INVALID_ARGUMENT);
323
324         if ((type < MM_PLAYER_STREAM_TYPE_DEFAULT) || (type > MM_PLAYER_STREAM_TYPE_TEXT))
325                 return MM_ERROR_INVALID_ARGUMENT;
326
327         *max_size = player->media_stream_buffer_max_size[type];
328
329         MMPLAYER_FLEAVE ();
330
331         return MM_ERROR_NONE;
332 }
333
334 int
335 _mmplayer_set_media_stream_min_percent(MMHandleType hplayer, MMPlayerStreamType type, guint min_percent)
336 {
337         mm_player_t *player = (mm_player_t *) hplayer;
338         GstElement *element = NULL;
339
340         MMPLAYER_FENTER ();
341
342         MMPLAYER_RETURN_VAL_IF_FAIL (player, MM_ERROR_PLAYER_NOT_INITIALIZED);
343
344         if ((type < MM_PLAYER_STREAM_TYPE_AUDIO) || (type > MM_PLAYER_STREAM_TYPE_TEXT)) {
345                 LOGE ("Invalid param type:%d", type);
346                 return MM_ERROR_INVALID_ARGUMENT;
347         }
348
349         LOGD ("type %d, min_per %u\n", type, min_percent);
350
351         if ((element = __mmplayer_get_source_element(player, type))) {
352                 LOGD ("update min_per of %s\n", GST_ELEMENT_NAME(element));
353                 g_object_set(G_OBJECT(element), "min-percent", min_percent, NULL);
354         }
355
356         player->media_stream_buffer_min_percent[type] = min_percent;
357
358         MMPLAYER_FLEAVE ();
359         return MM_ERROR_NONE;
360 }
361
362 int
363 _mmplayer_get_media_stream_min_percent(MMHandleType hplayer, MMPlayerStreamType type, guint *min_percent)
364 {
365         mm_player_t *player = (mm_player_t *) hplayer;
366
367         MMPLAYER_FENTER ();
368
369         MMPLAYER_RETURN_VAL_IF_FAIL (player, MM_ERROR_PLAYER_NOT_INITIALIZED);
370         MMPLAYER_RETURN_VAL_IF_FAIL (min_percent, MM_ERROR_INVALID_ARGUMENT);
371
372         if ((type < MM_PLAYER_STREAM_TYPE_DEFAULT) || (type > MM_PLAYER_STREAM_TYPE_TEXT))
373                 return MM_ERROR_INVALID_ARGUMENT;
374
375         *min_percent = player->media_stream_buffer_min_percent[type];
376
377         MMPLAYER_FLEAVE ();
378
379         return MM_ERROR_NONE;
380 }
381
382 static int
383 __mmplayer_check_buffer_level(mm_player_t *player, GstElement* element, MMPlayerStreamType type)
384 {
385         guint64 current_level_bytes = 0;
386         guint64 max_bytes = 0;
387         guint current_level_per = 0;
388
389         MMPLAYER_FENTER ();
390         MMPLAYER_RETURN_VAL_IF_FAIL ( player && element, MM_ERROR_PLAYER_NOT_INITIALIZED);
391
392         if (player->media_stream_buffer_max_size[type] > 0) {
393                 max_bytes = player->media_stream_buffer_max_size[type];
394         } else {
395                 g_object_get(G_OBJECT(element), "max-bytes", &max_bytes, NULL);
396         }
397
398         if (max_bytes == 0) {
399                 LOGW ("buffer max size is zero.");
400                 return MM_ERROR_NONE;
401         }
402
403         g_object_get(G_OBJECT(element), "current-level-bytes", &current_level_bytes, NULL);
404
405         if (max_bytes <= current_level_bytes) {
406                 LOGE ("no available buffer space. type %d, max %lld, curr %lld", type, max_bytes, current_level_bytes);
407                 return MM_ERROR_PLAYER_BUFFER_SPACE;
408         }
409
410         if (MMPLAYER_CURRENT_STATE(player) != MM_PLAYER_STATE_PLAYING) {
411                 if (!player->media_stream_buffer_status_cb[type]) {
412                         return MM_ERROR_NONE;
413                 }
414
415                 current_level_per = (guint)(gst_util_guint64_to_gdouble(current_level_bytes)/gst_util_guint64_to_gdouble(max_bytes)*100);
416
417                 LOGD ("type %d, min_per %u, curr_per %u max %lld cur %lld\n",
418                                         type, player->media_stream_buffer_min_percent[type],
419                                         current_level_per,
420                                         player->media_stream_buffer_max_size[type],
421                                         current_level_bytes);
422
423                 if (current_level_per < player->media_stream_buffer_min_percent[type])
424                         player->media_stream_buffer_status_cb[type](type, MM_PLAYER_MEDIA_STREAM_BUFFER_UNDERRUN, current_level_bytes, player->buffer_cb_user_param);
425         }
426
427         MMPLAYER_FLEAVE ();
428         return MM_ERROR_NONE;
429 }
430
431 int
432 _mmplayer_submit_packet (MMHandleType hplayer, media_packet_h packet)
433 {
434   int ret = MM_ERROR_NONE;
435   GstBuffer *_buffer = NULL;
436   mm_player_t *player = (mm_player_t *) hplayer;
437   guint8 *buf = NULL;
438   uint64_t size = 0;
439   GstElement* element = NULL;
440   MMPlayerStreamType streamtype = MM_PLAYER_STREAM_TYPE_AUDIO;
441   media_format_h fmt = NULL;
442   bool flag = FALSE;
443   bool is_eos = FALSE;
444
445   MMPLAYER_RETURN_VAL_IF_FAIL (packet, MM_ERROR_INVALID_ARGUMENT);
446   MMPLAYER_RETURN_VAL_IF_FAIL ( player &&
447     player->pipeline &&
448     player->pipeline->mainbin &&
449     player->pipeline->mainbin[MMPLAYER_M_SRC].gst,
450     MM_ERROR_PLAYER_INTERNAL );
451
452   /* get stream type if audio or video */
453   media_packet_is_audio (packet, &flag);
454   if (flag) {
455     streamtype = MM_PLAYER_STREAM_TYPE_AUDIO;
456   } else {
457     media_packet_is_video (packet, &flag);
458     if (flag)
459       streamtype = MM_PLAYER_STREAM_TYPE_VIDEO;
460         else
461       streamtype = MM_PLAYER_STREAM_TYPE_TEXT;
462   }
463
464   element = __mmplayer_get_source_element(player, streamtype);
465   if (!element) {
466       LOGE ("there is no source element of type %d", streamtype);
467       ret = MM_ERROR_PLAYER_INTERNAL;
468       goto ERROR;
469   }
470
471   /* check buffer level */
472   ret = __mmplayer_check_buffer_level (player, element, streamtype);
473   if (ret != MM_ERROR_NONE)
474     return ret;
475
476   /* get data */
477   if (media_packet_get_buffer_data_ptr (packet, (void **) &buf) != MEDIA_PACKET_ERROR_NONE) {
478     LOGE("failed to get buffer data ptr");
479     ret = MM_ERROR_PLAYER_INTERNAL;
480     goto ERROR;
481   }
482
483   if (media_packet_get_buffer_size (packet, &size) != MEDIA_PACKET_ERROR_NONE) {
484     LOGE("failed to get buffer size");
485     ret = MM_ERROR_PLAYER_INTERNAL;
486     goto ERROR;
487   }
488
489   if (buf != NULL && size > 0) {
490     GstMapInfo buff_info = GST_MAP_INFO_INIT;
491     uint64_t pts = 0;
492
493     /* get size */
494     _buffer = gst_buffer_new_and_alloc (size);
495
496     if (!_buffer) {
497         LOGE("failed to allocate memory for push buffer\n");
498         ret = MM_ERROR_PLAYER_NO_FREE_SPACE;
499         goto ERROR;
500     }
501
502     if (gst_buffer_map (_buffer, &buff_info, GST_MAP_READWRITE)) {
503
504       memcpy (buff_info.data, buf, size);
505       buff_info.size = size;
506
507       gst_buffer_unmap (_buffer, &buff_info);
508     }
509
510     if (streamtype == MM_PLAYER_STREAM_TYPE_VIDEO) {
511       /* get format to check video format */
512       media_packet_get_format (packet, &fmt);
513       if (fmt) {
514         if (_mmplayer_update_video_info(hplayer, fmt)) {
515           LOGD("update video caps");
516           g_object_set(G_OBJECT(player->pipeline->mainbin[MMPLAYER_M_SRC].gst),
517                                     "caps", player->v_stream_caps, NULL);
518         }
519       }
520     }
521
522     /* get pts */
523     if (media_packet_get_pts (packet, &pts) != MEDIA_PACKET_ERROR_NONE) {
524       LOGE("failed to get pts info");
525       ret = MM_ERROR_PLAYER_INTERNAL;
526       goto ERROR;
527     }
528     GST_BUFFER_PTS (_buffer) = (GstClockTime)pts;
529         gst_app_src_push_buffer (GST_APP_SRC (element), _buffer);
530   }
531
532   /* check eos */
533   if (media_packet_is_end_of_stream(packet, &is_eos) != MEDIA_PACKET_ERROR_NONE) {
534     LOGE("failed to get eos info");
535     ret = MM_ERROR_PLAYER_INTERNAL;
536     goto ERROR;
537   }
538
539   if (is_eos) {
540     LOGW ("we got eos of stream type(%d)", streamtype);
541         g_signal_emit_by_name (element, "end-of-stream", &ret);
542   }
543
544 ERROR:
545   return ret;
546 }
547
548 int
549 _mmplayer_video_caps_new (MMHandleType hplayer, MMPlayerVideoStreamInfo * video,
550     const char *fieldname, ...)
551 {
552   int cap_size;
553   GstCaps *caps = NULL;
554   GstStructure *structure = NULL;
555   va_list var_args;
556   mm_player_t *player = MM_PLAYER_CAST (hplayer);
557
558   MMPLAYER_FENTER ();
559   MMPLAYER_RETURN_VAL_IF_FAIL (player, MM_ERROR_PLAYER_NOT_INITIALIZED);
560   MMPLAYER_RETURN_VAL_IF_FAIL (video, MM_ERROR_PLAYER_NOT_INITIALIZED);
561
562   LOGD ("width=%d height=%d framerate num=%d, den=%d",
563     video->width, video->height, video->framerate_num, video->framerate_den);
564
565   caps = gst_caps_new_simple (video->mime,
566       "width", G_TYPE_INT, video->width,
567       "height", G_TYPE_INT, video->height,
568       "framerate", GST_TYPE_FRACTION, video->framerate_num, video->framerate_den, NULL);
569
570   for (cap_size = 0; cap_size < gst_caps_get_size (caps); cap_size++) {
571     va_start (var_args, fieldname);
572     structure = gst_caps_get_structure (caps, cap_size);
573     gst_structure_set_valist (structure, fieldname, var_args);
574     va_end (var_args);
575   }
576
577   if (video->extradata_size) {
578     GstBuffer *buf = NULL;
579     GstMapInfo buff_info = GST_MAP_INFO_INIT;
580
581     buf = gst_buffer_new_and_alloc (video->extradata_size);
582
583     if (gst_buffer_map (buf, &buff_info, GST_MAP_READ)) {
584       memcpy (buff_info.data, video->codec_extradata, video->extradata_size);
585       buff_info.size = video->extradata_size;
586       gst_buffer_unmap (buf, &buff_info);
587     }
588
589     gst_caps_set_simple (caps, "codec_data", GST_TYPE_BUFFER, buf, NULL);
590     gst_buffer_unref (buf);
591   }
592
593   if (player->v_stream_caps)
594   {
595     LOGW ("caps will be updated ");
596
597     gst_caps_unref(player->v_stream_caps);
598     player->v_stream_caps = NULL;
599   }
600
601   player->v_stream_caps = gst_caps_copy (caps);
602   MMPLAYER_LOG_GST_CAPS_TYPE (player->v_stream_caps);
603   gst_caps_unref (caps);
604
605   MMPLAYER_FLEAVE ();
606
607   return MM_ERROR_NONE;
608 }
609
610 static void
611 _mmplayer_set_uri_type(mm_player_t *player)
612 {
613         MMPLAYER_FENTER ();
614
615         player->profile.uri_type = MM_PLAYER_URI_TYPE_MS_BUFF;
616         player->es_player_push_mode = TRUE;
617
618         MMPLAYER_FLEAVE ();
619         return;
620 }
621
622 int
623 _mmplayer_set_video_info (MMHandleType hplayer, media_format_h format)
624 {
625   mm_player_t *player = MM_PLAYER_CAST (hplayer);
626   MMPlayerVideoStreamInfo video = { 0, };
627   int ret = MM_ERROR_NONE;
628
629   MMPLAYER_FENTER ();
630
631   MMPLAYER_RETURN_VAL_IF_FAIL (player, MM_ERROR_PLAYER_NOT_INITIALIZED);
632
633   _mmplayer_set_uri_type(player);
634
635   ret = _parse_media_format (&video, NULL, format);
636   if(ret != MM_ERROR_NONE)
637     return ret;
638
639   if (strstr (video.mime, "video/mpeg")) {
640     _mmplayer_video_caps_new (hplayer, &video,
641         "mpegversion", G_TYPE_INT, video.version,
642         "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
643   } else if (strstr (video.mime, "video/x-h264")) {
644     //if (info.colordepth)
645     {
646       //      _mmplayer_video_caps_new(hplayer, &info,
647       //              "colordepth", G_TYPE_INT, info.colordepth, NULL);
648     }
649     //else
650     {
651       _mmplayer_video_caps_new (hplayer, &video,
652           "stream-format", G_TYPE_STRING, "byte-stream",
653           "alignment", G_TYPE_STRING, "au", NULL);
654     }
655   }
656 #if 0
657   else if (strstr (info->mime, "video/x-wmv")) {
658     _mmplayer_video_caps_new (hplayer, &info,
659         "wmvversion", G_TYPE_INT, info.version, NULL);
660   } else if (strstr (info.mime, "video/x-pn-realvideo")) {
661     _mmplayer_video_caps_new (hplayer, &info,
662         "rmversion", G_TYPE_INT, info.version, NULL);
663   } else if (strstr (info.mime, "video/x-msmpeg")) {
664     _mmplayer_video_caps_new (hplayer, &info,
665         "msmpegversion", G_TYPE_INT, info.version, NULL);
666   } else if (strstr (info.mime, "video/x-h265")) {
667     if (info.colordepth) {
668       _mmplayer_video_caps_new (hplayer, &info,
669           "colordepth", G_TYPE_INT, info.colordepth, NULL);
670     } else {
671       _mmplayer_video_caps_new (hplayer, &info, NULL);
672     }
673   } else {
674     _mmplayer_video_caps_new (hplayer, &info, NULL);
675   }
676 #endif
677   g_free ((char *) video.mime);
678
679   MMPLAYER_FLEAVE ();
680
681   return MM_ERROR_NONE;
682 }
683
684 int
685 _mmplayer_set_audio_info (MMHandleType hplayer, media_format_h format)
686 {
687   mm_player_t *player = MM_PLAYER_CAST (hplayer);
688   GstCaps *caps = NULL;
689   MMPlayerAudioStreamInfo audio = { 0, };
690   int ret = MM_ERROR_NONE;
691
692   MMPLAYER_FENTER ();
693
694   MMPLAYER_RETURN_VAL_IF_FAIL (hplayer, MM_ERROR_PLAYER_NOT_INITIALIZED);
695
696   _mmplayer_set_uri_type(player);
697
698   ret = _parse_media_format (NULL, &audio, format);
699   if(ret != MM_ERROR_NONE)
700     return ret;
701
702   audio.user_info = 0;           //test
703
704   LOGD ("set audio player[%p] info [%p] version=%d rate=%d channel=%d",
705       player, audio, audio.version, audio.sample_rate, audio.channels);
706
707   if (strstr (audio.mime, "audio/mpeg")) {
708     if (audio.version == 1) {   // mp3
709       caps = gst_caps_new_simple ("audio/mpeg",
710           "channels", G_TYPE_INT, audio.channels,
711           "rate", G_TYPE_INT, audio.sample_rate,
712           "mpegversion", G_TYPE_INT, audio.version,
713           "layer", G_TYPE_INT, audio.user_info, NULL);
714     } else {                    // aac
715       gchar *format = NULL;
716
717       if (audio.user_info == 0)
718         format = g_strdup ("raw");
719       else if (audio.user_info == 1)
720         format = g_strdup ("adts");
721       else if (audio.user_info == 2)
722         format = g_strdup ("adif");
723
724       caps = gst_caps_new_simple ("audio/mpeg",
725           "channels", G_TYPE_INT, audio.channels,
726           "rate", G_TYPE_INT, audio.sample_rate,
727           "mpegversion", G_TYPE_INT, audio.version,
728           "stream-format", G_TYPE_STRING, format, NULL);
729
730       g_free (format);
731       format = NULL;
732     }
733   }
734 #if 0
735   else if (strstr (audio.mime, "audio/x-raw-int")) {
736     caps = gst_caps_new_simple ("audio/x-raw-int",
737         "width", G_TYPE_INT, audio.width,
738         "depth", G_TYPE_INT, audio.depth,
739         "endianness", G_TYPE_INT, audio.endianness,
740         "signed", G_TYPE_BOOLEAN, audio.signedness,
741         "channels", G_TYPE_INT, audio.channels,
742         "rate", G_TYPE_INT, audio.sample_rate, NULL);
743   } else {
744     caps = gst_caps_new_simple (audio.mime,
745         "channels", G_TYPE_INT, audio.channels,
746         "rate", G_TYPE_INT, audio.sample_rate, NULL);
747   }
748 #endif
749
750   if (audio.extradata_size) {
751     GstBuffer *buf = NULL;
752     GstMapInfo buff_info = GST_MAP_INFO_INIT;
753
754     buf = gst_buffer_new_and_alloc (audio.extradata_size);
755
756     if (gst_buffer_map (buf, &buff_info, GST_MAP_READ)) {
757       memcpy (buff_info.data, audio.codec_extradata, audio.extradata_size);
758       gst_buffer_unmap (buf, &buff_info);
759     }
760
761     gst_caps_set_simple (caps, "codec_data", GST_TYPE_BUFFER, buf, NULL);
762     gst_buffer_unref (buf);
763   }
764
765   g_free ((char *) audio.mime);
766
767   player->a_stream_caps = gst_caps_copy (caps);
768   gst_caps_unref (caps);
769
770   MMPLAYER_FLEAVE ();
771
772   return MM_ERROR_NONE;
773 }
774
775 int
776 _mmplayer_set_subtitle_info (MMHandleType hplayer,
777     MMPlayerSubtitleStreamInfo * subtitle)
778 {
779 #if 0                           //todo
780
781   mm_player_t *player = MM_PLAYER_CAST (hplayer);
782   GstCaps *caps = NULL;
783
784   MMPLAYER_FENTER ();
785
786   MMPLAYER_RETURN_VAL_IF_FAIL (player, MM_ERROR_PLAYER_NOT_INITIALIZED);
787   MMPLAYER_RETURN_VAL_IF_FAIL (info, MM_ERROR_PLAYER_NOT_INITIALIZED);
788
789   LOGD ("set subtitle player[%p] info [%p]", player, info);
790
791
792   caps = gst_caps_new_simple (info->mime, NULL, NULL);  // TO CHECK
793   if (NULL == caps)
794     return FALSE;
795
796   if (strstr (info->mime, "application/x-xsub")) {
797     gst_caps_set_simple (caps, "codec_tag", G_TYPE_UINT, info->codec_tag, NULL);
798   } else if (strstr (info->mime, "application/x-smpte-text")) {
799     if (info->context) {
800       gst_caps_set_simple (caps, "ttml_priv_data", G_TYPE_POINTER,
801           info->context, NULL);
802     }
803   }
804
805   player->s_stream_caps = gst_caps_copy (caps);
806
807   gst_caps_unref (caps);
808 #endif
809
810   MMPLAYER_FLEAVE ();
811
812   return MM_ERROR_NONE;
813 }