#define __TIZEN_MEDIA_CODEC_BITSTREAM_H__
#include <tizen.h>
-#include <media_codec_port.h>
+#include <media_codec_private.h>
typedef struct _mc_bitstream_t mc_bitstream_t;
void _mc_create_decoder_map_from_ini(mc_handle_t *mc_handle);
void _mc_create_encoder_map_from_ini(mc_handle_t *mc_handle);
-const int simple_to_codec_type_enumeration(codec_type_e codec_id);
-const int codec_type_to_simple_enumeration(mediacodec_codec_type_e media_codec_id);
+const codec_type_e simple_to_codec_type_enumeration(codec_type_e codec_id);
+const codec_type_e codec_type_to_simple_enumeration(mediacodec_codec_type_e media_codec_id);
#ifdef __cplusplus
}
#include <tizen.h>
#include <stdint.h>
+#include <glib.h>
#include <media_codec.h>
int __mc_decode_sps(mc_bitstream_t *pstream, int *width, int *height)
{
- int ret = MC_ERROR_NONE;
+ int ret = 0;
unsigned int tmp = 0;
int profile_idc = 0;
profile_idc = tmp;
if (profile_idc > 51)
- ret = MC_INVALID_IN_BUF;
+ ret = -1;
/*TODO parse width, height, etc...*/
switch (syntax & 0x1F) {
case NAL_SEQUENCE_PARAMETER_SET:
LOGD("nal_unit_type : SPS");
- if ((ret = __mc_decode_sps(&pstream, NULL, NULL)) != MC_ERROR_NONE)
+ if ((ret = __mc_decode_sps(&pstream, NULL, NULL)) != -1)
return ret;
state |= MC_EXIST_SPS;
codec_length += nal_length;
/* input port */
if (!port && !CHECK_VALID_PACKET(state, MC_VALID_FIRST_SLICE))
- return MC_INVALID_IN_BUF;
+ return -1;
/* output port */
if (port) {
} while (count == 1 && p < end);
if (count != 1)
- return MC_INVALID_IN_BUF; /* frame boundary violated */
+ return -1; /* frame boundary violated */
- return MC_ERROR_NONE;
+ return 0;
}
bool _mc_is_voss(unsigned char *buf, int size, int *codec_size)
int _mc_check_mpeg4_out_bytestream(unsigned char *buf, int buf_length, bool* need_codec_data, bool *need_sync_flag)
{
int codec_data_size = 0;
- g_return_val_if_fail(need_codec_data != NULL, MC_PARAM_ERROR);
- g_return_val_if_fail(need_sync_flag != NULL, MC_PARAM_ERROR);
*need_codec_data = FALSE;
*need_sync_flag = FALSE;
bool _mc_check_h263_out_bytestream(unsigned char *p, int buf_length, bool* need_sync_flag)
{
- g_return_val_if_fail(need_sync_flag != NULL, MC_PARAM_ERROR);
-
*need_sync_flag = FALSE;
/* PSC not present */
data_size = _mc_check_h264_bytestream(data, size, 0, NULL, NULL, NULL);
if (data_size <= 0) {
LOGE("No valid SPS/PPS ...");
- return MC_INVALID_IN_BUF;
+ return -1;
}
return data_size;
} else {
/* parse the avcC data */
if (size < 7) { /* when numSPS==0 and numPPS==0, length is 7 bytes */
LOGE("If contains codec_data, size should over 7 bytes ...");
- return MC_INVALID_IN_BUF;
+ return -1;
}
/* parse the version, this must be 1 */
if (data[0] != 1) {
LOGE("If contains codec_data, first byte must be 1 ...");
- return MC_INVALID_IN_BUF;
+ return -1;
}
num_sps = data[5] & 0x1f;
return offset;
}
- return MC_INVALID_IN_BUF;
+ return -1;
}
}
return ret;
ERROR:
-
+ g_free(new_mediacodec);
return MC_INVALID_ARG;
}
{
int ret = MEDIACODEC_NONE;
int i;
- int index = 0;
+ int index;
gboolean codec[CODEC_NR_ITEMS] = {0,};
for (i = 0; i < mc_ini.num_supported_codecs; i++) {
- index = codec_type_to_simple_enumeration(spec_emul[i].codec_id);
+ index = (int)codec_type_to_simple_enumeration(spec_emul[i].codec_id);
codec[index] = TRUE;
}
for (i = 0; i < CODEC_NR_ITEMS; i++) {
if (codec[i]) {
- index = simple_to_codec_type_enumeration(i);
+ index = (int)simple_to_codec_type_enumeration(i);
if (!callback(index, user_data))
goto CALLBACK_ERROR;
}
return;
}
-const int codec_type_to_simple_enumeration(mediacodec_codec_type_e media_codec_id)
+const codec_type_e codec_type_to_simple_enumeration(mediacodec_codec_type_e media_codec_id)
{
guint media_codec_id_u = (guint)media_codec_id;
}
}
-const int simple_to_codec_type_enumeration(codec_type_e codec_id)
+const codec_type_e simple_to_codec_type_enumeration(codec_type_e codec_id)
{
guint codec_id_u = (guint)codec_id;
* limitations under the License.
*
*/
-#include <glib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
ret = media_packet_create_from_external_memory(core->output_fmt, ext_mem, mem_size, __mc_output_buffer_finalize_cb, mcbuffer, &packet);
if (ret != MEDIA_PACKET_ERROR_NONE) {
LOGW("media_packet_create_alloc failed");
+ g_free(ext_mem);
return MC_ERROR;
}
mcbuffer->packet = packet;
bool slice = FALSE;
gint mem_size = 0;
gchar *ext_mem = NULL;
+ gint data_size = 0;
void *packet_data = NULL;
media_packet_h packet = NULL;
case MEDIA_FORMAT_H264_SP:
case MEDIA_FORMAT_H264_MP:
case MEDIA_FORMAT_H264_HP:
- ret = _mc_check_h264_bytestream((unsigned char *)data, size, 1, &codec_config, &sync_flag, &slice);
+ data_size = _mc_check_h264_bytestream((unsigned char *)data, size, 1, &codec_config, &sync_flag, &slice);
+
+ if (data_size <= 0) {
+ LOGE("No valid SPS/PPS ...");
+ return MC_INVALID_IN_BUF;
+ }
break;
case MEDIA_FORMAT_MPEG4_SP:
case MEDIA_FORMAT_MPEG4_ASP:
ret = media_packet_create_from_external_memory(core->output_fmt, ext_mem, mem_size, __mc_output_buffer_finalize_cb, mcbuffer, &packet);
if (ret != MEDIA_PACKET_ERROR_NONE) {
LOGW("media_packet_create_alloc failed");
+ g_free(ext_mem);
return MC_ERROR;
}
mcbuffer->packet = packet;
ret = media_packet_create_from_external_memory(core->output_fmt, ext_mem, mem_size, __mc_output_buffer_finalize_cb, mcbuffer, &packet);
if (ret != MEDIA_PACKET_ERROR_NONE) {
LOGW("media_packet_create_alloc failed");
+ g_free(ext_mem);
return MC_ERROR;
}
mcbuffer->packet = packet;
gst_buffer_map(core->codec_data, &map, GST_MAP_READ);
ptr = map.data;
len = map.size;
- media_packet_set_codec_data(packet, ptr, len);
+ ret = media_packet_set_codec_data(packet, ptr, len);
+ if (ret != MEDIA_PACKET_ERROR_NONE) {
+ LOGW("media_packet_set_codec_data failed");
+ gst_buffer_unmap(core->codec_data, &map);
+ return MC_ERROR;
+ }
gst_buffer_unmap(core->codec_data, &map);
}
media_packet_h pkt = NULL;
guint8 *tmp;
gint read;
- gint size;
- gint offset;
gint stride_width;
gboolean codec_config = FALSE;
/* Y */
media_packet_get_video_plane_data_ptr(pkt, 0, (void **)&buf_data_ptr);
media_packet_get_video_stride_width(pkt, 0, &stride_width);
- offset = app->width*app->height;
for (j = 0; j < app->height; j++) {
memcpy(buf_data_ptr, tmp, app->width);
if (app->hardware == TRUE) {
media_packet_get_video_plane_data_ptr(pkt, 1, (void **)&buf_data_ptr);
media_packet_get_video_stride_width(pkt, 1, &stride_width);
- size = app->width * app->height / 2;
for (j = 0; j < app->height / 2; j++) {
memcpy(buf_data_ptr, tmp, app->width);
/* U */
media_packet_get_video_plane_data_ptr(pkt, 1, (void **)&buf_data_ptr);
media_packet_get_video_stride_width(pkt, 1, &stride_width);
- size = (app->width>>1) * (app->height>>1);
for (j = 0; j < app->height/2; j++) {
memcpy(buf_data_ptr, tmp, app->width/2);
/* V */
media_packet_get_video_plane_data_ptr(pkt, 2, (void **)&buf_data_ptr);
media_packet_get_video_stride_width(pkt, 2, &stride_width);
- offset += size;
for (j = 0; j < app->height/2; j++) {
memcpy(buf_data_ptr, tmp, app->width/2);
guint8 *tmp;
gint i;
gint read;
- gint size;
- gint offset;
gint stride_width;
if (app->offset == 0) {
/* Y */
media_packet_get_video_plane_data_ptr(pkt, 0, (void **)&buf_data_ptr);
media_packet_get_video_stride_width(pkt, 0, &stride_width);
- offset = app->width*app->height;
for (i = 0; i < app->height; i++) {
memcpy(buf_data_ptr, tmp, app->width);
if (app->hardware == TRUE) {
media_packet_get_video_plane_data_ptr(pkt, 1, (void **)&buf_data_ptr);
media_packet_get_video_stride_width(pkt, 1, &stride_width);
- size = app->width * app->height>>1;
for (i = 0; i < app->height>>1; i++) {
memcpy(buf_data_ptr, tmp, app->width);
/* U */
media_packet_get_video_plane_data_ptr(pkt, 1, (void **)&buf_data_ptr);
media_packet_get_video_stride_width(pkt, 1, &stride_width);
- size = (app->width>>1) * (app->height>>1);
for (i = 0; i < app->height/2; i++) {
memcpy(buf_data_ptr, tmp, app->width>>1);
/* V */
media_packet_get_video_plane_data_ptr(pkt, 2, (void **)&buf_data_ptr);
media_packet_get_video_stride_width(pkt, 2, &stride_width);
- offset += size;
for (i = 0; i < app->height/2; i++) {
memcpy(buf_data_ptr, tmp, app->width>>1);
guint8 *temp;
int i = 0;
int stride_width, stride_height;
- gchar filename[100] = {0};
+ gchar filename[256] = {0, };
FILE *fp = NULL;
int ret = 0;
{
void *temp;
uint64_t buf_size;
- gchar filename[100] = {0};
+ gchar filename[256] = {0, };
FILE *fp = NULL;
int ret = 0;
char adts[100] = {0, };
default:
return "NONE";
}
- return "NONE";
}
int main(int argc, char *argv[])