Skip to content

Commit bcfea42

Browse files
committed
auto-detect cpd
1 parent 599a068 commit bcfea42

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

kinesis-video-gst-demo/kinesis_video_gstreamer_sample_app.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ SampleStreamCallbackProvider::droppedFrameReportHandler(UINT64 custom_data, STRE
131131
} // namespace amazonaws
132132
} // namespace com;
133133

134-
const unsigned char cpd[] = { 0x01, 0x42, 0x00, 0x20, 0xff, 0xe1, 0x00, 0x23, 0x27, 0x42, 0x00, 0x20, 0x89, 0x8b, 0x60, 0x28, 0x02, 0xdd, 0x80, 0x9e, 0x00, 0x00, 0x4e, 0x20, 0x00, 0x0f, 0x42, 0x41, 0xc0, 0xc0, 0x01, 0x77, 0x00, 0x00, 0x5d, 0xc1, 0x7b, 0xdf, 0x07, 0xc2, 0x21, 0x1b, 0x80, 0x01, 0x00, 0x04, 0x28, 0xce, 0x1f, 0x20 };
135134
unique_ptr<Credentials> credentials_;
136135

137136
typedef struct _CustomData {
@@ -140,6 +139,7 @@ typedef struct _CustomData {
140139
GMainLoop *main_loop;
141140
unique_ptr<KinesisVideoProducer> kinesis_video_producer;
142141
shared_ptr<KinesisVideoStream> kinesis_video_stream;
142+
bool stream_started;
143143
} CustomData;
144144

145145
void create_kinesis_video_frame(Frame *frame, const nanoseconds &pts, const nanoseconds &dts, FRAME_FLAGS flags,
@@ -160,6 +160,16 @@ bool put_frame(shared_ptr<KinesisVideoStream> kinesis_video_stream, void *data,
160160

161161
static GstFlowReturn on_new_sample(GstElement *sink, CustomData *data) {
162162
GstSample *sample = gst_app_sink_pull_sample(GST_APP_SINK (sink));
163+
GstCaps* gstcaps = (GstCaps*) gst_sample_get_caps(sample);
164+
GstStructure * gststructforcaps = gst_caps_get_structure(gstcaps, 0);
165+
166+
if (!data->stream_started) {
167+
data->stream_started = true;
168+
const GValue *gstStreamFormat = gst_structure_get_value(gststructforcaps, "codec_data");
169+
gchar *cpd = gst_value_serialize(gstStreamFormat);
170+
data->kinesis_video_stream->start(std::string(cpd));
171+
}
172+
163173
GstBuffer *buffer = gst_sample_get_buffer(sample);
164174
size_t buffer_size = gst_buffer_get_size(buffer);
165175
uint8_t *frame_data = new uint8_t[buffer_size];
@@ -266,8 +276,8 @@ void kinesis_video_init(CustomData *data, char *stream_name) {
266276
seconds(30),
267277
"V_MPEG4/ISO/AVC",
268278
"kinesis_video",
269-
cpd,
270-
sizeof(cpd));
279+
nullptr,
280+
0);
271281
data->kinesis_video_stream = data->kinesis_video_producer->createStreamSync(move(stream_definition));
272282

273283
LOG_DEBUG("Stream is ready");

0 commit comments

Comments
 (0)