Initial release
[platform/hal/api/codec.git] / tests / codec_hal_test.cpp
1 /*
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
3  *
4  * Contact: Jeongmo Yang <jm80.yang@samsung.com>
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18
19 #include <glib.h>
20 #include <string.h>
21 #include <gtest/gtest.h>
22 #include <gst/gst.h>
23 #include <unistd.h>
24 #include <iostream>
25 #include <iniparser.h>
26 #include <gst/app/gstappsrc.h>
27 #include <gst/allocators/gsttizenmemory.h>
28 #include <tbm_surface_internal.h>
29
30 using namespace std;
31 typedef struct _codec_list_t codec_list_t;
32 #define CNAME_SIZE 512
33 #define CODEC_INI_MAX_STRLEN     256
34 #define DEFAULT_PORT "GST_PORT"
35 #define CODEC_INI_DEFAULT_PATH   SYSCONFDIR"/multimedia/mmfw_media_codec.ini"
36
37 #define CODEC_INI_GET_STRING(x_dict, x_item, x_ini, x_default) \
38 do {\
39         const char *str = iniparser_getstring(x_dict, x_ini, x_default); \
40         \
41         if (str &&  \
42                         (strlen(str) > 0) && \
43                         (strlen(str) < CODEC_INI_MAX_STRLEN)) \
44                 strncpy(x_item, str, strlen(str) + 1); \
45         else \
46                 strncpy(x_item, x_default, strlen(x_default) + 1); \
47 } while (0)
48
49 typedef enum {
50         H263,
51         H264,
52         MPEG4
53 } codec_list_e;
54
55 struct _codec_list_t {
56         codec_list_e ename;
57         char cname[CODEC_INI_MAX_STRLEN];
58         char plugins[2][CODEC_INI_MAX_STRLEN];
59 };
60
61 static codec_list_t codec_list[] = {
62         { H263, "h263", },
63         { H264, "h264", },
64         { MPEG4, "mpeg4" },
65 };
66
67 void get_plugins_list_from_ini(dictionary *dict, codec_list_t *codec_list, int codec_num)
68 {
69         int i, j;
70         int index = 0;
71         char *token = NULL;
72         char *usr_ptr = NULL;
73         const char *delimiters = " ,";
74         size_t len;
75         char port_name[CNAME_SIZE];
76         char temp[CNAME_SIZE];
77         char cname[CNAME_SIZE];
78         const char *type[2];
79         type[0] = ":hw_decoder";
80         type[1] = ":hw_encoder";
81
82         CODEC_INI_GET_STRING(dict, port_name, (char *)"port_in_use:media_codec_port", (char *)DEFAULT_PORT);
83
84         if (strcmp(port_name, DEFAULT_PORT) == 0) {
85                 for (i = 0; i < 2; i++) {
86                         for (j = 0; j < codec_num; j++) {
87                                 index = 0;
88
89                                 snprintf(cname, CNAME_SIZE, "%s", codec_list[j].cname);
90                                 len = strlen(cname);
91                                 snprintf(cname + len, CNAME_SIZE - len, "%s", type[i]);
92                                 CODEC_INI_GET_STRING(dict, temp, cname, (char *)"");
93                                 token = strtok_r(temp, delimiters, &usr_ptr);
94
95                                 while (token) {
96                                         if (token && index == 0)
97                                                 strncpy(codec_list[j].plugins[i], token, strlen(token) + 1);
98                                         token = strtok_r(NULL, delimiters, &usr_ptr);
99                                         index++;
100                                 }
101                         }
102                 }
103         }
104 }
105
106 static void
107 pad_added_cb(GstElement * demux, GstPad * pad, GstBin * pipeline)
108 {
109         GstElement *sink, *parse, *codec;
110         GstCaps *caps;
111
112         GST_INFO_OBJECT(pad, "got pad");
113
114         caps = gst_pad_query_caps(pad, NULL);
115         gchar *caps_str = gst_caps_to_string(caps);
116         gst_caps_unref(caps);
117
118         if (strstr(caps_str, "h264")) {
119                 parse = gst_element_factory_make("h264parse", NULL);
120                 codec = gst_element_factory_make(codec_list[H264].plugins[0], NULL);
121         } else if (strstr(caps_str, "h263")) {
122                 parse = gst_element_factory_make("h263parse", NULL);
123                 codec = gst_element_factory_make(codec_list[H263].plugins[0], NULL);
124         } else if (strstr(caps_str, "video/mpeg")) {
125                 parse = gst_element_factory_make("mpeg4videoparse", NULL);
126                 codec = gst_element_factory_make(codec_list[MPEG4].plugins[0], NULL);
127         } else {
128                 GST_WARNING_OBJECT(pad, "non video pad");
129                 g_free(caps_str);
130                 return;
131         }
132
133         sink = gst_element_factory_make("fakesink", NULL);
134         gst_bin_add_many(GST_BIN(pipeline), parse, codec, sink, NULL);
135         gst_element_link_many(demux, parse, codec, sink, NULL);
136
137         gst_element_set_state(parse, GST_STATE_PAUSED);
138         gst_element_set_state(codec, GST_STATE_PAUSED);
139         gst_element_set_state(sink, GST_STATE_PAUSED);
140         g_free(caps_str);
141 }
142
143 static GstBusSyncReply
144 error_cb(GstBus * bus, GstMessage * msg, gpointer user_data)
145 {
146         if (GST_MESSAGE_TYPE(msg) == GST_MESSAGE_ERROR) {
147                 const gchar *file = (const gchar *)user_data;
148                 GError *err = NULL;
149                 gchar *dbg = NULL;
150
151                 gst_message_parse_error(msg, &err, &dbg);
152                 g_error("ERROR for %s: %s\n%s\n", file, err->message, dbg);
153         }
154
155         return GST_BUS_PASS;
156 }
157
158 gboolean bus_callback(GstBus *bus, GstMessage *msg, gpointer data)
159 {
160         switch (GST_MESSAGE_TYPE(msg)) {
161         case GST_MESSAGE_EOS:
162                 break;
163         case GST_MESSAGE_ERROR:
164                 break;
165         default:
166                 break;
167         }
168         return TRUE;
169 }
170
171 void buffer_add(GstElement *element, GstBuffer *buffer, GstPad *pad, gpointer data)
172 {
173 }
174
175 /*
176  * main class
177  */
178 class CodecHalTest : public testing::Test
179 {
180         public:
181
182                 virtual void SetUp()
183                 {
184                         return;
185                 }
186
187                 virtual void TearDown()
188                 {
189
190                         return;
191                 }
192
193 };
194
195 /**
196  * @testcase            InitH263DecoderP
197  * @since_tizen         6.5
198  * @author                      SR(jm80.yang)
199  * @reviewer            SR(heechul.jeon)
200  * @type                        auto
201  * @description         Positive, Initialize H.263 Decoder Plugin
202  * @apicovered          N/A
203  * @passcase            when h263 decoder plugin exists pipeline can be changed to GST_STATE_PAUSED
204  * @failcase            when the state is not changed to GST_STATE_PAUSED
205  * @precondition        None
206  * @postcondition       None
207  */
208 TEST_F(CodecHalTest, InitH263DecoderP)
209 {
210         GstElement *sink, *src, *codec, *pipeline;
211         GstStateChangeReturn ret;
212
213         pipeline = gst_pipeline_new("pipeline");
214         src = gst_element_factory_make("fakesrc", NULL);
215         codec = gst_element_factory_make(codec_list[H263].plugins[0], NULL);
216         sink = gst_element_factory_make("fakesink", NULL);
217
218         gst_bin_add_many(GST_BIN(pipeline), src, codec, sink, NULL);
219
220         ret = gst_element_set_state(pipeline, GST_STATE_PAUSED);
221         EXPECT_NE(ret, GST_STATE_CHANGE_FAILURE);
222
223         gst_object_unref(pipeline);
224 }
225
226 /**
227  * @testcase            InitH264DecoderP
228  * @since_tizen         6.5
229  * @author                      SR(jm80.yang)
230  * @reviewer            SR(heechul.jeon)
231  * @type                        auto
232  * @description         Positive, Initialize H.263 Decoder Plugin
233  * @apicovered          N/A
234  * @passcase            when h264 decoder plugin exists pipeline can be changed to GST_STATE_PAUSED
235  * @failcase            when the state is not changed to GST_STATE_PAUSED
236  * @precondition        None
237  * @postcondition       None
238  */
239 TEST_F(CodecHalTest, InitH264DecoderP)
240 {
241         GstElement *sink, *src, *codec, *pipeline;
242         GstStateChangeReturn ret;
243
244         pipeline = gst_pipeline_new("pipeline");
245         src = gst_element_factory_make("fakesrc", NULL);
246         codec = gst_element_factory_make(codec_list[H264].plugins[0], NULL);
247         sink = gst_element_factory_make("fakesink", NULL);
248
249         gst_bin_add_many(GST_BIN(pipeline), src, codec, sink, NULL);
250
251         ret = gst_element_set_state(pipeline, GST_STATE_PAUSED);
252         EXPECT_NE(ret, GST_STATE_CHANGE_FAILURE);
253
254         gst_object_unref(pipeline);
255 }
256
257 /**
258  * @testcase            InitMpeg4DecoderP
259  * @since_tizen         6.5
260  * @author                      SR(jm80.yang)
261  * @reviewer            SR(heechul.jeon)
262  * @type                        auto
263  * @description         Positive, Initialize MPEG4 Decoder Plugin
264  * @apicovered          N/A
265  * @passcase            when MPEG4 decoder plugin exists pipeline can be changed to GST_STATE_PAUSED
266  * @failcase            when the state is not changed to GST_STATE_PAUSED
267  * @precondition        None
268  * @postcondition       None
269  */
270 TEST_F(CodecHalTest, InitMpeg4DecoderP)
271 {
272         GstElement *sink, *src, *codec, *pipeline;
273         GstStateChangeReturn ret;
274
275         pipeline = gst_pipeline_new("pipeline");
276         src = gst_element_factory_make("fakesrc", NULL);
277         codec = gst_element_factory_make(codec_list[MPEG4].plugins[0], NULL);
278         sink = gst_element_factory_make("fakesink", NULL);
279
280         gst_bin_add_many(GST_BIN(pipeline), src, codec, sink, NULL);
281
282         ret = gst_element_set_state(pipeline, GST_STATE_PAUSED);
283         EXPECT_NE(ret, GST_STATE_CHANGE_FAILURE);
284
285         gst_object_unref(pipeline);
286 }
287
288 /**
289  * @testcase            InitH263EncoderP
290  * @since_tizen         6.5
291  * @author                      SR(jm80.yang)
292  * @reviewer            SR(heechul.jeon)
293  * @type                        auto
294  * @description         Positive, Initialize H.263 Encoder Plugin
295  * @apicovered          N/A
296  * @passcase            when H.263 encoder plugin exists pipeline can be changed to GST_STATE_PAUSED
297  * @failcase            when the state is not changed to GST_STATE_PAUSED
298  * @precondition        None
299  * @postcondition       None
300  */
301 TEST_F(CodecHalTest, InitH263EncoderP)
302 {
303         GstElement *sink, *src, *codec, *pipeline;
304         GstStateChangeReturn ret;
305
306         pipeline = gst_pipeline_new("pipeline");
307         src = gst_element_factory_make("fakesrc", NULL);
308         codec = gst_element_factory_make(codec_list[H263].plugins[1], NULL);
309         sink = gst_element_factory_make("fakesink", NULL);
310
311         gst_bin_add_many(GST_BIN(pipeline), src, codec, sink, NULL);
312
313         ret = gst_element_set_state(pipeline, GST_STATE_PAUSED);
314         EXPECT_NE(ret, GST_STATE_CHANGE_FAILURE);
315
316         gst_object_unref(pipeline);
317 }
318
319 /**
320  * @testcase            InitH264EncoderP
321  * @since_tizen         6.5
322  * @author                      SR(jm80.yang)
323  * @reviewer            SR(heechul.jeon)
324  * @type                        auto
325  * @description         Positive, Initialize H.264 Encoder Plugin
326  * @apicovered          N/A
327  * @passcase            when H.264 encoder plugin exists pipeline can be changed to GST_STATE_PAUSED
328  * @failcase            when the state is not changed to GST_STATE_PAUSED
329  * @precondition        None
330  * @postcondition       None
331  */
332 TEST_F(CodecHalTest, InitH264EncoderP)
333 {
334         GstElement *sink, *src, *codec, *pipeline;
335         GstStateChangeReturn ret;
336
337         pipeline = gst_pipeline_new("pipeline");
338         src = gst_element_factory_make("fakesrc", NULL);
339         codec = gst_element_factory_make(codec_list[H264].plugins[1], NULL);
340         sink = gst_element_factory_make("fakesink", NULL);
341
342         gst_bin_add_many(GST_BIN(pipeline), src, codec, sink, NULL);
343
344         ret = gst_element_set_state(pipeline, GST_STATE_PAUSED);
345         EXPECT_NE(ret, GST_STATE_CHANGE_FAILURE);
346
347         gst_object_unref(pipeline);
348 }
349
350 /**
351  * @testcase            InitMPEG4EncoderP
352  * @since_tizen         6.5
353  * @author                      SR(jm80.yang)
354  * @reviewer            SR(heechul.jeon)
355  * @type                        auto
356  * @description         Positive, Initialize H.264 Encoder Plugin
357  * @apicovered          N/A
358  * @passcase            when MPEG4 encoder plugin exists pipeline can be changed to GST_STATE_PAUSED
359  * @failcase            when the state is not changed to GST_STATE_PAUSED
360  * @precondition        None
361  * @postcondition       None
362  */
363 TEST_F(CodecHalTest, InitMpeg4EncoderP)
364 {
365         GstElement *sink, *src, *codec, *pipeline;
366         GstStateChangeReturn ret;
367
368         pipeline = gst_pipeline_new("pipeline");
369         src = gst_element_factory_make("fakesrc", NULL);
370         codec = gst_element_factory_make(codec_list[MPEG4].plugins[1], NULL);
371         sink = gst_element_factory_make("fakesink", NULL);
372
373         gst_bin_add_many(GST_BIN(pipeline), src, codec, sink, NULL);
374
375         ret = gst_element_set_state(pipeline, GST_STATE_PAUSED);
376         EXPECT_NE(ret, GST_STATE_CHANGE_FAILURE);
377
378         gst_object_unref(pipeline);
379 }
380
381 /**
382  * @testcase            DecodeH264P
383  * @since_tizen         6.5
384  * @author                      SR(jm80.yang)
385  * @reviewer            SR(heechul.jeon)
386  * @type                        auto
387  * @description         Positive, Decode H.264 Decoder Plugin
388  * @apicovered          N/A
389  * @passcase            when h264 decoder decode stream, pipeline can be changed to GST_STATE_PLAYING
390  * @failcase            when the state is not changed to GST_STATE_PLAYING
391  * @precondition        None
392  * @postcondition       None
393  */
394 TEST_F(CodecHalTest, DecodeH264P)
395 {
396         GstStateChangeReturn state_ret;
397         GstElement *src, *demux, *pipeline;
398         GstMessage *msg;
399         GstBus *bus;
400         gchar *path;
401
402         pipeline = gst_pipeline_new("pipeline");
403
404         src = gst_element_factory_make("filesrc", NULL);
405
406         demux = gst_element_factory_make("qtdemux", NULL);
407
408         bus = gst_element_get_bus(pipeline);
409
410         /* kids, don't use a sync handler for this at home, really; we do because
411          * we just want to abort and nothing else */
412         gst_bus_set_sync_handler(bus, error_cb, (gpointer) "meerkat.mp4", NULL);
413
414         gst_bin_add_many(GST_BIN(pipeline), src, demux, NULL);
415
416         gst_element_link(src, demux);
417
418         path = g_build_filename(TEST_FILES_PATH, "meerkat.mp4", NULL);
419         GST_INFO("reading file '%s'", path);
420         g_object_set(src, "location", path, NULL);
421
422         /* can't link uridecodebin and sink yet, do that later */
423         g_signal_connect(demux, "pad-added", G_CALLBACK(pad_added_cb), pipeline);
424
425         state_ret = gst_element_set_state(pipeline, GST_STATE_PAUSED);
426
427         if (state_ret == GST_STATE_CHANGE_ASYNC) {
428                 GST_INFO("waiting for pipeline to reach PAUSED state");
429                 state_ret = gst_element_get_state(pipeline, NULL, NULL, -1);
430         }
431
432         state_ret = gst_element_set_state(pipeline, GST_STATE_PLAYING);
433         EXPECT_NE(state_ret, GST_STATE_CHANGE_FAILURE);
434
435         GST_INFO("PAUSED, let's decode");
436         msg = gst_bus_timed_pop_filtered(bus, 10 * GST_SECOND, GST_MESSAGE_EOS);
437         GST_INFO("Done, got EOS message");
438
439         gst_message_unref(msg);
440         gst_object_unref(bus);
441
442         gst_element_set_state(pipeline, GST_STATE_NULL);
443         EXPECT_EQ(state_ret, GST_STATE_CHANGE_SUCCESS);
444
445         gst_object_unref(pipeline);
446         g_free(path);
447 }
448
449 /**
450  * @testcase            DecodeH263P
451  * @since_tizen         6.5
452  * @author                      SR(jm80.yang)
453  * @reviewer            SR(heechul.jeon)
454  * @type                        auto
455  * @description         Positive, Decode H.263 Decoder Plugin
456  * @apicovered          N/A
457  * @passcase            when h263 decoder decode stream, pipeline can be changed to GST_STATE_PLAYING
458  * @failcase            when the state is not changed to GST_STATE_PLAYING
459  * @precondition        None
460  * @postcondition       None
461  */
462 TEST_F(CodecHalTest, DecodeH263P)
463 {
464         GstStateChangeReturn state_ret;
465         GstElement *src, *demux, *pipeline;
466         GstMessage *msg;
467         GstBus *bus;
468         gchar *path;
469
470         pipeline = gst_pipeline_new("pipeline");
471
472         src = gst_element_factory_make("filesrc", NULL);
473
474         demux = gst_element_factory_make("qtdemux", NULL);
475
476         bus = gst_element_get_bus(pipeline);
477
478         /* kids, don't use a sync handler for this at home, really; we do because
479          * we just want to abort and nothing else */
480         gst_bus_set_sync_handler(bus, error_cb, (gpointer)"she.3gp", NULL);
481
482         gst_bin_add_many(GST_BIN(pipeline), src, demux, NULL);
483
484         gst_element_link(src, demux);
485
486         path = g_build_filename(TEST_FILES_PATH, "she.3gp", NULL);
487         GST_INFO("reading file '%s'", path);
488         g_object_set(src, "location", path, NULL);
489
490         /* can't link uridecodebin and sink yet, do that later */
491         g_signal_connect(demux, "pad-added", G_CALLBACK(pad_added_cb), pipeline);
492
493         state_ret = gst_element_set_state(pipeline, GST_STATE_PAUSED);
494
495         if (state_ret == GST_STATE_CHANGE_ASYNC) {
496                 GST_INFO("waiting for pipeline to reach PAUSED state");
497                 state_ret = gst_element_get_state(pipeline, NULL, NULL, -1);
498         }
499
500         state_ret = gst_element_set_state(pipeline, GST_STATE_PLAYING);
501         EXPECT_NE(state_ret, GST_STATE_CHANGE_FAILURE);
502
503         GST_INFO("PAUSED, let's decode");
504         msg = gst_bus_timed_pop_filtered(bus, 10 * GST_SECOND, GST_MESSAGE_EOS);
505         GST_INFO("Done, got EOS message");
506
507         gst_message_unref(msg);
508         gst_object_unref(bus);
509
510         state_ret = gst_element_set_state(pipeline, GST_STATE_NULL);
511         EXPECT_EQ(state_ret, GST_STATE_CHANGE_SUCCESS);
512         gst_object_unref(pipeline);
513
514         g_free(path);
515 }
516
517 /**
518  * @testcase            DecodeMPEG4P
519  * @since_tizen         6.5
520  * @author                      SR(jm80.yang)
521  * @reviewer            SR(heechul.jeon)
522  * @type                        auto
523  * @description         Positive, Decode MPEG4 Decoder Plugin
524  * @apicovered          N/A
525  * @passcase            when MPEG4 decoder decode stream, pipeline can be changed to GST_STATE_PLAYING
526  * @failcase            when the state is not changed to GST_STATE_PLAYING
527  * @precondition        None
528  * @postcondition       None
529  */
530 TEST_F(CodecHalTest, DecodeMPEG4P)
531 {
532         GstStateChangeReturn state_ret;
533         GstElement *src, *demux, *pipeline;
534         GstMessage *msg;
535         GstBus *bus;
536         gchar *path;
537
538         pipeline = gst_pipeline_new("pipeline");
539
540         src = gst_element_factory_make("filesrc", NULL);
541
542         demux = gst_element_factory_make("qtdemux", NULL);
543
544         bus = gst_element_get_bus(pipeline);
545
546         /* kids, don't use a sync handler for this at home, really; we do because
547          * we just want to abort and nothing else */
548         gst_bus_set_sync_handler(bus, error_cb, (gpointer)"mv.MP4", NULL);
549
550         gst_bin_add_many(GST_BIN(pipeline), src, demux, NULL);
551
552         gst_element_link(src, demux);
553
554         path = g_build_filename(TEST_FILES_PATH, "mv.MP4", NULL);
555         GST_INFO("reading file '%s'", path);
556         g_object_set(src, "location", path, NULL);
557
558         /* can't link uridecodebin and sink yet, do that later */
559         g_signal_connect(demux, "pad-added", G_CALLBACK(pad_added_cb), pipeline);
560
561         state_ret = gst_element_set_state(pipeline, GST_STATE_PAUSED);
562
563         if (state_ret == GST_STATE_CHANGE_ASYNC) {
564                 GST_INFO("waiting for pipeline to reach PAUSED state");
565                 state_ret = gst_element_get_state(pipeline, NULL, NULL, -1);
566         }
567
568         state_ret = gst_element_set_state(pipeline, GST_STATE_PLAYING);
569         EXPECT_NE(state_ret, GST_STATE_CHANGE_FAILURE);
570
571         GST_INFO("PAUSED, let's decode");
572         msg = gst_bus_timed_pop_filtered(bus, 10 * GST_SECOND, GST_MESSAGE_EOS);
573         GST_INFO("Done, got EOS message");
574
575         gst_message_unref(msg);
576         gst_object_unref(bus);
577
578         state_ret = gst_element_set_state(pipeline, GST_STATE_NULL);
579         EXPECT_EQ(state_ret, GST_STATE_CHANGE_SUCCESS);
580         gst_object_unref(pipeline);
581
582         g_free(path);
583 }
584
585 #if 0
586 /**
587  * @testcase            EncodeH264P
588  * @since_tizen         6.5
589  * @author                      SR(jm80.yang)
590  * @reviewer            SR(heechul.jeon)
591  * @type                        auto
592  * @description         Positive, Encode H.264 Decoder Plugin
593  * @apicovered          N/A
594  * @passcase            when H.264 encoder encode buffer, outbuffer will be dequed
595  * @failcase            when the state is not changed to GST_STATE_PLAYING or the error occur
596  * @precondition        None
597  * @postcondition       None
598  */
599 TEST_F(CodecHalTest, EncodeH264P)
600 {
601         GstStateChangeReturn state_ret;
602         GstElement *sink, *src, *codec, *pipeline;
603         GstMessage *msg;
604         GstBus *bus;
605         gchar *path;
606         gint bus_watch_id;
607         gulong signal_handoff;
608         GstBuffer *buffer;
609         GstAllocator *allocator;
610         GstMemory *mem;
611         GstVideoInfo vinfo;
612         tbm_surface_h surface;
613         int i;
614         int ret;
615
616         pipeline = gst_pipeline_new("pipeline");
617
618         src = gst_element_factory_make("appsrc", NULL);
619
620         codec = gst_element_factory_make(codec_list[H264].plugins[1], NULL);
621
622         bus = gst_element_get_bus(pipeline);
623         bus_watch_id = gst_bus_add_watch(bus, bus_callback, NULL);
624         gst_bin_add_many(GST_BIN(pipeline), src, codec, sink, NULL);
625         gst_element_link_many(src, codec, sink, NULL);
626
627         signal_handoff = g_signal_connect(sink, "handoff", G_CALLBACK(buffer_add), NULL);
628         state_ret = gst_element_set_state(pipeline, GST_STATE_PAUSED);
629
630         if (state_ret == GST_STATE_CHANGE_ASYNC) {
631                 GST_INFO("waiting for pipeline to reach PAUSED state");
632                 state_ret = gst_element_get_state(pipeline, NULL, NULL, -1);
633         }
634
635         state_ret = gst_element_set_state(pipeline, GST_STATE_PLAYING);
636         EXPECT_NE(state_ret, GST_STATE_CHANGE_FAILURE);
637
638         allocator = gst_tizen_allocator_new();
639
640         for (i = 0; i < 5; i++) {
641                 surface = tbm_surface_internal_create_with_flags(640, 480, TBM_FORMAT_NV12, TBM_BO_NONCACHABLE);
642                 mem = gst_tizen_allocator_alloc_surface(allocator, &vinfo, surface, NULL, NULL);
643                 gst_buffer_append_memory(buffer, mem);
644                 ret = gst_app_src_push_buffer((GstAppSrc*)src, buffer);
645         }
646
647         g_signal_handler_disconnect(sink, signal_handoff);
648         gst_object_unref(bus);
649
650         state_ret = gst_element_set_state(pipeline, GST_STATE_NULL);
651         EXPECT_EQ(state_ret, GST_STATE_CHANGE_SUCCESS);
652
653         gst_object_unref(pipeline);
654 }
655
656 /**
657  * @testcase            EncodeH263P
658  * @since_tizen         6.5
659  * @author                      SR(jm80.yang)
660  * @reviewer            SR(heechul.jeon)
661  * @type                        auto
662  * @description         Positive, Encode H.263 Decoder Plugin
663  * @apicovered          N/A
664  * @passcase            when H.263 encoder encode buffer, outbuffer will be dequed
665  * @failcase            when the state is not changed to GST_STATE_PLAYING or the error occur
666  * @precondition        None
667  * @postcondition       None
668  */
669 TEST_F(CodecHalTest, EncodeH263P)
670 {
671         GstStateChangeReturn state_ret;
672         GstElement *sink, *src, *codec, *pipeline;
673         GstMessage *msg;
674         GstBus *bus;
675         gchar *path;
676         gint bus_watch_id;
677
678         pipeline = gst_pipeline_new("pipeline");
679
680         src = gst_element_factory_make("appsrc", NULL);
681
682         codec = gst_element_factory_make(codec_list[H263].plugins[1], NULL);
683
684         bus = gst_element_get_bus(pipeline);
685         bus_watch_id = gst_bus_add_watch(bus, bus_callback, NULL);
686         gst_bin_add_many(GST_BIN(pipeline), src, codec, sink, NULL);
687         gst_element_link_many(src, codec, sink, NULL);
688
689         state_ret = gst_element_set_state(pipeline, GST_STATE_PAUSED);
690
691         if (state_ret == GST_STATE_CHANGE_ASYNC) {
692                 GST_INFO("waiting for pipeline to reach PAUSED state");
693                 state_ret = gst_element_get_state(pipeline, NULL, NULL, -1);
694         }
695
696         state_ret = gst_element_set_state(pipeline, GST_STATE_PLAYING);
697         EXPECT_NE(state_ret, GST_STATE_CHANGE_FAILURE);
698
699         GST_INFO("PAUSED, let's encode");
700         gst_object_unref(bus);
701
702         state_ret = gst_element_set_state(pipeline, GST_STATE_NULL);
703         EXPECT_EQ(state_ret, GST_STATE_CHANGE_SUCCESS);
704         gst_object_unref(pipeline);
705 }
706
707 /**
708  * @testcase            EncodeMPEG4P
709  * @since_tizen         6.5
710  * @author                      SR(jm80.yang)
711  * @reviewer            SR(heechul.jeon)
712  * @type                        auto
713  * @description         Positive, Encode MPEG4 Decoder Plugin
714  * @apicovered          N/A
715  * @passcase            when MPEG4 encoder encode buffer, outbuffer will be dequed
716  * @failcase            when the state is not changed to GST_STATE_PLAYING or the error occur
717  * @precondition        None
718  * @postcondition       None
719  */
720 TEST_F(CodecHalTest, EncodeMPEG4P)
721 {
722         GstStateChangeReturn state_ret;
723         GstElement *sink, *src, *codec, *pipeline;
724         GstMessage *msg;
725         GstBus *bus;
726         gchar *path;
727         gint bus_watch_id;
728
729         pipeline = gst_pipeline_new("pipeline");
730
731         src = gst_element_factory_make("appsrc", NULL);
732
733         codec = gst_element_factory_make(codec_list[MPEG4].plugins[1], NULL);
734
735         bus = gst_element_get_bus(pipeline);
736         bus_watch_id = gst_bus_add_watch(bus, bus_callback, NULL);
737         gst_bin_add_many(GST_BIN(pipeline), src, codec, sink, NULL);
738         gst_element_link_many(src, codec, sink, NULL);
739
740         state_ret = gst_element_set_state(pipeline, GST_STATE_PAUSED);
741
742         if (state_ret == GST_STATE_CHANGE_ASYNC) {
743                 GST_INFO("waiting for pipeline to reach PAUSED state");
744                 state_ret = gst_element_get_state(pipeline, NULL, NULL, -1);
745         }
746
747         state_ret = gst_element_set_state(pipeline, GST_STATE_PLAYING);
748         EXPECT_NE(state_ret, GST_STATE_CHANGE_FAILURE);
749
750         GST_INFO("PAUSED, let's encode");
751         gst_object_unref(bus);
752
753         state_ret = gst_element_set_state(pipeline, GST_STATE_NULL);
754         EXPECT_EQ(state_ret, GST_STATE_CHANGE_SUCCESS);
755         gst_object_unref(pipeline);
756 }
757 #endif
758
759 int main(int argc, char **argv)
760 {
761         int codec_num;
762         dictionary *dict;
763
764         gst_init(&argc, &argv);
765         dict = iniparser_load(CODEC_INI_DEFAULT_PATH);
766
767         codec_num = sizeof(codec_list) / sizeof(codec_list[0]);
768         get_plugins_list_from_ini(dict, codec_list, codec_num);
769         iniparser_freedict(dict);
770         testing::InitGoogleTest(&argc, argv);
771
772         return RUN_ALL_TESTS();
773 }