• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GStreamer
2  *
3  * Copyright (C) 2020 Seungha Yang <seungha@centricular.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24 
25 #include <gst/check/gstcheck.h>
26 #include <gst/check/gstharness.h>
27 #include <gst/video/video.h>
28 
GST_START_TEST(test_videoenc_drain)29 GST_START_TEST (test_videoenc_drain)
30 {
31   GstHarness *h;
32   GstVideoInfo info;
33   GstBuffer *in_buf;
34   gint i = 0;
35   gint num_output = 0;
36   GstFlowReturn ret;
37   GstSegment segment;
38   GstCaps *caps;
39 
40   h = gst_harness_new ("avenc_mjpeg");
41   fail_unless (h != NULL);
42 
43   caps = gst_caps_from_string ("video/x-raw,format=I420,width=64,height=64");
44 
45   gst_harness_set_src_caps (h, gst_caps_copy (caps));
46   gst_video_info_set_format (&info, GST_VIDEO_FORMAT_I420, 64, 64);
47 
48   for (i = 0; i < 2; i++) {
49     in_buf = gst_buffer_new_and_alloc (GST_VIDEO_INFO_SIZE (&info));
50 
51     GST_BUFFER_PTS (in_buf) = i * GST_SECOND;
52     GST_BUFFER_DURATION (in_buf) = GST_SECOND;
53 
54     ret = gst_harness_push (h, in_buf);
55 
56     fail_unless (ret == GST_FLOW_OK, "GstFlowReturn was %s",
57         gst_flow_get_name (ret));
58   }
59 
60   gst_segment_init (&segment, GST_FORMAT_TIME);
61   fail_unless (gst_segment_set_running_time (&segment, GST_FORMAT_TIME,
62           2 * GST_SECOND));
63 
64   /* Push new eos event to drain encoder */
65   fail_unless (gst_harness_push_event (h, gst_event_new_eos ()));
66 
67   /* And start new stream */
68   fail_unless (gst_harness_push_event (h,
69           gst_event_new_stream_start ("new-stream-id")));
70   gst_harness_set_src_caps (h, caps);
71   fail_unless (gst_harness_push_event (h, gst_event_new_segment (&segment)));
72 
73   in_buf = gst_buffer_new_and_alloc (GST_VIDEO_INFO_SIZE (&info));
74 
75   GST_BUFFER_PTS (in_buf) = 2 * GST_SECOND;
76   GST_BUFFER_DURATION (in_buf) = GST_SECOND;
77 
78   ret = gst_harness_push (h, in_buf);
79   fail_unless (ret == GST_FLOW_OK, "GstFlowReturn was %s",
80       gst_flow_get_name (ret));
81 
82   /* Finish encoding and drain again */
83   fail_unless (gst_harness_push_event (h, gst_event_new_eos ()));
84   do {
85     GstBuffer *out_buf = NULL;
86 
87     out_buf = gst_harness_try_pull (h);
88     if (out_buf) {
89       num_output++;
90       gst_buffer_unref (out_buf);
91       continue;
92     }
93 
94     break;
95   } while (1);
96 
97   fail_unless_equals_int (num_output, 3);
98 
99   gst_harness_teardown (h);
100 }
101 
102 GST_END_TEST;
103 
104 static Suite *
avvidenc_suite(void)105 avvidenc_suite (void)
106 {
107   Suite *s = suite_create ("avvidenc");
108   TCase *tc_chain = tcase_create ("general");
109 
110   suite_add_tcase (s, tc_chain);
111   tcase_add_test (tc_chain, test_videoenc_drain);
112 
113   return s;
114 }
115 
116 GST_CHECK_MAIN (avvidenc)
117