Check supported HW codec
[platform/hal/api/codec.git] / tests / codec_hal_test.cpp
index 63b78f2..58dfc1b 100644 (file)
@@ -52,6 +52,11 @@ typedef enum {
        MPEG4
 } codec_list_e;
 
+typedef enum {
+       DECODER,
+       ENCODER
+} codec_type_e;
+
 struct _codec_list_t {
        codec_list_e ename;
        char cname[CODEC_INI_MAX_STRLEN];
@@ -76,8 +81,8 @@ void get_plugins_list_from_ini(dictionary *dict, codec_list_t *codec_list, int c
        char temp[CNAME_SIZE];
        char cname[CNAME_SIZE];
        const char *type[2];
-       type[0] = ":hw_decoder";
-       type[1] = ":hw_encoder";
+       type[DECODER] = ":hw_decoder";
+       type[ENCODER] = ":hw_encoder";
 
        CODEC_INI_GET_STRING(dict, port_name, (char *)"port_in_use:media_codec_port", (char *)DEFAULT_PORT);
 
@@ -117,13 +122,13 @@ pad_added_cb(GstElement * demux, GstPad * pad, GstBin * pipeline)
 
        if (strstr(caps_str, "h264")) {
                parse = gst_element_factory_make("h264parse", NULL);
-               codec = gst_element_factory_make(codec_list[H264].plugins[0], NULL);
+               codec = gst_element_factory_make(codec_list[H264].plugins[DECODER], NULL);
        } else if (strstr(caps_str, "h263")) {
                parse = gst_element_factory_make("h263parse", NULL);
-               codec = gst_element_factory_make(codec_list[H263].plugins[0], NULL);
+               codec = gst_element_factory_make(codec_list[H263].plugins[DECODER], NULL);
        } else if (strstr(caps_str, "video/mpeg")) {
                parse = gst_element_factory_make("mpeg4videoparse", NULL);
-               codec = gst_element_factory_make(codec_list[MPEG4].plugins[0], NULL);
+               codec = gst_element_factory_make(codec_list[MPEG4].plugins[DECODER], NULL);
        } else {
                GST_WARNING_OBJECT(pad, "non video pad");
                g_free(caps_str);
@@ -172,6 +177,16 @@ void buffer_add(GstElement *element, GstBuffer *buffer, GstPad *pad, gpointer da
 {
 }
 
+static gboolean __is_hw_codec_supported(codec_list_e codec, codec_type_e type)
+{
+       if (strlen(codec_list[codec].plugins[type]) == 0) {
+               std::cout << "NO HW CODEC SUPPORTED" << std::endl;
+               return FALSE;
+       }
+
+       return TRUE;
+}
+
 /*
  * main class
  */
@@ -210,9 +225,12 @@ TEST_F(CodecHalTest, InitH263DecoderP)
        GstElement *sink, *src, *codec, *pipeline;
        GstStateChangeReturn ret;
 
+       if (!__is_hw_codec_supported(H263, DECODER))
+               return;
+
        pipeline = gst_pipeline_new("pipeline");
        src = gst_element_factory_make("fakesrc", NULL);
-       codec = gst_element_factory_make(codec_list[H263].plugins[0], NULL);
+       codec = gst_element_factory_make(codec_list[H263].plugins[DECODER], NULL);
        sink = gst_element_factory_make("fakesink", NULL);
 
        gst_bin_add_many(GST_BIN(pipeline), src, codec, sink, NULL);
@@ -241,9 +259,12 @@ TEST_F(CodecHalTest, InitH264DecoderP)
        GstElement *sink, *src, *codec, *pipeline;
        GstStateChangeReturn ret;
 
+       if (!__is_hw_codec_supported(H264, DECODER))
+               return;
+
        pipeline = gst_pipeline_new("pipeline");
        src = gst_element_factory_make("fakesrc", NULL);
-       codec = gst_element_factory_make(codec_list[H264].plugins[0], NULL);
+       codec = gst_element_factory_make(codec_list[H264].plugins[DECODER], NULL);
        sink = gst_element_factory_make("fakesink", NULL);
 
        gst_bin_add_many(GST_BIN(pipeline), src, codec, sink, NULL);
@@ -272,9 +293,12 @@ TEST_F(CodecHalTest, InitMpeg4DecoderP)
        GstElement *sink, *src, *codec, *pipeline;
        GstStateChangeReturn ret;
 
+       if (!__is_hw_codec_supported(MPEG4, DECODER))
+               return;
+
        pipeline = gst_pipeline_new("pipeline");
        src = gst_element_factory_make("fakesrc", NULL);
-       codec = gst_element_factory_make(codec_list[MPEG4].plugins[0], NULL);
+       codec = gst_element_factory_make(codec_list[MPEG4].plugins[DECODER], NULL);
        sink = gst_element_factory_make("fakesink", NULL);
 
        gst_bin_add_many(GST_BIN(pipeline), src, codec, sink, NULL);
@@ -303,9 +327,12 @@ TEST_F(CodecHalTest, InitH263EncoderP)
        GstElement *sink, *src, *codec, *pipeline;
        GstStateChangeReturn ret;
 
+       if (!__is_hw_codec_supported(H263, ENCODER))
+               return;
+
        pipeline = gst_pipeline_new("pipeline");
        src = gst_element_factory_make("fakesrc", NULL);
-       codec = gst_element_factory_make(codec_list[H263].plugins[1], NULL);
+       codec = gst_element_factory_make(codec_list[H263].plugins[ENCODER], NULL);
        sink = gst_element_factory_make("fakesink", NULL);
 
        gst_bin_add_many(GST_BIN(pipeline), src, codec, sink, NULL);
@@ -334,9 +361,12 @@ TEST_F(CodecHalTest, InitH264EncoderP)
        GstElement *sink, *src, *codec, *pipeline;
        GstStateChangeReturn ret;
 
+       if (!__is_hw_codec_supported(H264, ENCODER))
+               return;
+
        pipeline = gst_pipeline_new("pipeline");
        src = gst_element_factory_make("fakesrc", NULL);
-       codec = gst_element_factory_make(codec_list[H264].plugins[1], NULL);
+       codec = gst_element_factory_make(codec_list[H264].plugins[ENCODER], NULL);
        sink = gst_element_factory_make("fakesink", NULL);
 
        gst_bin_add_many(GST_BIN(pipeline), src, codec, sink, NULL);
@@ -365,9 +395,12 @@ TEST_F(CodecHalTest, InitMpeg4EncoderP)
        GstElement *sink, *src, *codec, *pipeline;
        GstStateChangeReturn ret;
 
+       if (!__is_hw_codec_supported(MPEG4, ENCODER))
+               return;
+
        pipeline = gst_pipeline_new("pipeline");
        src = gst_element_factory_make("fakesrc", NULL);
-       codec = gst_element_factory_make(codec_list[MPEG4].plugins[1], NULL);
+       codec = gst_element_factory_make(codec_list[MPEG4].plugins[ENCODER], NULL);
        sink = gst_element_factory_make("fakesink", NULL);
 
        gst_bin_add_many(GST_BIN(pipeline), src, codec, sink, NULL);
@@ -399,6 +432,9 @@ TEST_F(CodecHalTest, DecodeH264P)
        GstBus *bus;
        gchar *path;
 
+       if (!__is_hw_codec_supported(H264, DECODER))
+               return;
+
        pipeline = gst_pipeline_new("pipeline");
 
        src = gst_element_factory_make("filesrc", NULL);
@@ -467,6 +503,9 @@ TEST_F(CodecHalTest, DecodeH263P)
        GstBus *bus;
        gchar *path;
 
+       if (!__is_hw_codec_supported(H263, DECODER))
+               return;
+
        pipeline = gst_pipeline_new("pipeline");
 
        src = gst_element_factory_make("filesrc", NULL);
@@ -535,6 +574,9 @@ TEST_F(CodecHalTest, DecodeMPEG4P)
        GstBus *bus;
        gchar *path;
 
+       if (!__is_hw_codec_supported(MPEG4, DECODER))
+               return;
+
        pipeline = gst_pipeline_new("pipeline");
 
        src = gst_element_factory_make("filesrc", NULL);
@@ -617,7 +659,7 @@ TEST_F(CodecHalTest, EncodeH264P)
 
        src = gst_element_factory_make("appsrc", NULL);
 
-       codec = gst_element_factory_make(codec_list[H264].plugins[1], NULL);
+       codec = gst_element_factory_make(codec_list[H264].plugins[ENCODER], NULL);
 
        bus = gst_element_get_bus(pipeline);
        bus_watch_id = gst_bus_add_watch(bus, bus_callback, NULL);
@@ -679,7 +721,7 @@ TEST_F(CodecHalTest, EncodeH263P)
 
        src = gst_element_factory_make("appsrc", NULL);
 
-       codec = gst_element_factory_make(codec_list[H263].plugins[1], NULL);
+       codec = gst_element_factory_make(codec_list[H263].plugins[ENCODER], NULL);
 
        bus = gst_element_get_bus(pipeline);
        bus_watch_id = gst_bus_add_watch(bus, bus_callback, NULL);
@@ -730,7 +772,7 @@ TEST_F(CodecHalTest, EncodeMPEG4P)
 
        src = gst_element_factory_make("appsrc", NULL);
 
-       codec = gst_element_factory_make(codec_list[MPEG4].plugins[1], NULL);
+       codec = gst_element_factory_make(codec_list[MPEG4].plugins[ENCODER], NULL);
 
        bus = gst_element_get_bus(pipeline);
        bus_watch_id = gst_bus_add_watch(bus, bus_callback, NULL);