+
+static gboolean
+__mm_player_is_codec_data_changed(mmplayer_t *player, media_packet_h packet,
+ mmplayer_stream_type_e streamtype)
+{
+ GstCaps *cur_caps = NULL;
+ GstCaps *new_caps = NULL;
+ GstStructure *str = NULL;
+ const GValue *value = NULL;
+ GstBuffer *buffer = NULL;
+ GstMapInfo codec_data_map = GST_MAP_INFO_INIT;
+ GstBuffer *new_buffer = NULL;
+ char *codec_data = NULL;
+ unsigned int codec_data_size = 0;
+
+ MMPLAYER_RETURN_VAL_IF_FAIL(player, FALSE);
+ MMPLAYER_RETURN_VAL_IF_FAIL(packet, FALSE);
+
+ if (media_packet_get_codec_data(packet, (void **)&codec_data, &codec_data_size)
+ != MEDIA_PACKET_ERROR_NONE)
+ return FALSE;
+
+ if (codec_data_size == 0) {
+ LOGW("codec_data_size is zero");
+ return FALSE;
+ }
+
+ if (streamtype == MM_PLAYER_STREAM_TYPE_AUDIO) {
+ cur_caps = player->a_stream_caps;
+ } else if (streamtype == MM_PLAYER_STREAM_TYPE_VIDEO) {
+ cur_caps = player->v_stream_caps;
+ } else {
+ LOGW("streamtype is not audio or video");
+ return FALSE;
+ }
+
+ if (!cur_caps) {
+ LOGW("Current caps is NULL");
+ return FALSE;
+ }
+
+ str = gst_caps_get_structure(cur_caps, 0);
+ if (!str) {
+ LOGW("Failed to get caps info");
+ return FALSE;
+ }
+
+ /* Check if the codec data in the saved caps have been changed */
+ value = gst_structure_get_value(str, "codec_data");
+ if (value) {
+ int i = 0;
+ buffer = gst_value_get_buffer(value);
+ if (!gst_buffer_map(buffer, &codec_data_map, GST_MAP_READ)) {
+ LOGW("codec data buffer map failed");
+ return FALSE;
+ }
+ if (codec_data_map.size == codec_data_size) {
+ for (i = 0; i <= codec_data_map.size; i++) {
+ if (codec_data_map.data[i] != codec_data[i])
+ break;
+ }
+ gst_buffer_unmap(buffer, &codec_data_map);
+ return FALSE;
+ }
+ gst_buffer_unmap(buffer, &codec_data_map);
+ }
+
+ new_caps = gst_caps_copy(cur_caps);
+ if (!new_caps) {
+ LOGW("Failed to copy caps");
+ return FALSE;
+ }
+
+ new_buffer = gst_buffer_new_allocate(NULL, codec_data_size, NULL);
+ if (!new_buffer) {
+ LOGW("Failed to alloc gst buffer for codec data");
+ gst_caps_unref(new_caps);
+ return FALSE;
+ }
+ gst_buffer_fill(new_buffer, 0, codec_data, codec_data_size);
+ gst_caps_set_simple(new_caps, "codec_data", GST_TYPE_BUFFER, new_buffer, NULL);
+ gst_buffer_unref(new_buffer);
+
+ if (streamtype == MM_PLAYER_STREAM_TYPE_AUDIO)
+ player->a_stream_caps = new_caps;
+ else if (streamtype == MM_PLAYER_STREAM_TYPE_VIDEO)
+ player->v_stream_caps = new_caps;
+
+ gst_caps_unref(cur_caps);
+
+ LOGD("need to update caps due to codec data is changed");
+ return TRUE;
+}