1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
/**
* Parrot Drones Awesome Video Viewer Library
*
* Copyright (c) 2018 Parrot Drones SAS
* Copyright (c) 2016 Aurelien Barre
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _PDRAW_H_
#define _PDRAW_H_
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#include <inttypes.h>
#include "pdraw_defs.h"
/* Forward declarations */
struct pdraw;
struct pdraw_demuxer;
struct pdraw_muxer;
struct pdraw_video_renderer;
struct pdraw_coded_video_sink;
struct pdraw_raw_video_sink;
/* General callback functions */
struct pdraw_cbs {
/* Stop response callback function, called when a stop operation is
* complete or has failed (optional, can be null, but highly recommended
* for correct PDrAW session management).
* The status parameter is the stop operation status: 0 on success,
* or a negative errno value in case of error.
* @param pdraw: PDrAW instance handle
* @param status: 0 on success, negative errno value in case of error
* @param userdata: user data pointer */
void (*stop_resp)(struct pdraw *pdraw, int status, void *userdata);
/* Media added callback function, called when a media has been added
* internally in the PDrAW pipeline. Medias are for example raw or coded
* video medias. The info structure gives the media identifier that can
* be used for example to create a video sink on this media.
* @param pdraw: PDrAW instance handle
* @param info: pointer on the media information
* @param userdata: user data pointer */
void (*media_added)(struct pdraw *pdraw,
const struct pdraw_media_info *info,
void *userdata);
/* Media removed callback function, called when a media has been removed
* internally from the PDrAW pipeline. Medias are for example raw or
* coded video medias. When a media is removed, any video sink created
* on this media must then be stopped.
* @param pdraw: PDrAW instance handle
* @param info: pointer on the media information
* @param userdata: user data pointer */
void (*media_removed)(struct pdraw *pdraw,
const struct pdraw_media_info *info,
void *userdata);
/* Socket creation callback function, called immediately after a
* socket creation with its file descriptor as parameter (optional,
* can be null).
* @param pdraw: PDrAW instance handle
* @param fd: socket file descriptor
* @param userdata: user data pointer */
void (*socket_created)(struct pdraw *pdraw, int fd, void *userdata);
};
/* Demuxer callback functions */
struct pdraw_demuxer_cbs {
/* Open response callback function, called when an open operation is
* complete or has failed (optional, can be null, but highly recommended
* for correct PDrAW session management).
* The status parameter is the open operation status: 0 on success,
* or a negative errno value in case of error.
* If this function reports an error, the demuxer still needs to be
* closed: pdraw_demuxer_close() must be called and one must wait for
* the close_resp callback function to be issued prior to calling
* pdraw_demuxer_destroy().
* @param pdraw: PDrAW instance handle
* @param demuxer: demuxer handle
* @param status: 0 on success, negative errno value in case of error
* @param userdata: user data pointer */
void (*open_resp)(struct pdraw *pdraw,
struct pdraw_demuxer *demuxer,
int status,
void *userdata);
/* Close response callback function, called when a close operation is
* complete or has failed (optional, can be null, but highly recommended
* for correct PDrAW session management).
* The status parameter is the close operation status: 0 on success,
* or a negative errno value in case of error.
* @param pdraw: PDrAW instance handle
* @param demuxer: demuxer handle
* @param status: 0 on success, negative errno value in case of error
* @param userdata: user data pointer */
void (*close_resp)(struct pdraw *pdraw,
struct pdraw_demuxer *demuxer,
int status,
void *userdata);
/* Unrecoverable error callback function, called when a previously
* opened session is no longer running. When this function is called,
* the demuxer session is no longer running; pdraw_demuxer_close() must
* be called and one must wait for the close_resp callback function to
* be issued prior to calling pdraw_demuxer_destroy().
* @param pdraw: PDrAW instance handle
* @param demuxer: demuxer handle
* @param userdata: user data pointer */
void (*unrecoverable_error)(struct pdraw *pdraw,
struct pdraw_demuxer *demuxer,
void *userdata);
/* Demuxer media selection callback function, called with a list of
* video medias found from which the application must choose one or more
* to process in the pipeline. The return value of the callback function
* must be a bitfield of the identifiers of the chosen medias (from the
* pdraw_demuxer_media structure), or 0 to choose the default medias. If
* the return value is -ENOSYS, the callback is considered not
* implemented and the default medias are chosen. If the return value is
* -ECANCELED no media is chosen and the open operation is aborted. If
* the return value is another negative errno or an invalid bitfield the
* open_resp callback function will be called if an open operation is in
* progress, or the unrecoverable_error callback function otherwise.
* @param pdraw: PDrAW instance handle
* @param demuxer: demuxer handle
* @param medias: array of demuxer media
* @param count: demuxer media array element count
* @param userdata: user data pointer
* @return a bitfield of the identifiers of the chosen medias,
* 0 or -ENOSYS to choose the default medias,
* -ECANCELED to choose no media and abort the open operation,
* or another negative errno value in case of error */
int (*select_media)(struct pdraw *pdraw,
struct pdraw_demuxer *demuxer,
const struct pdraw_demuxer_media *medias,
size_t count,
void *userdata);
/* Ready to play callback function, called when the playback is ready
* to start (optional, can be null). This function is called to indicate
* that the PDrAW session is ready to process play operations.
* Generally the session is ready to play as soon as the open_resp
* callback function has been called with a success status. One case
* when the open operation was successful and the playback is not ready
* is when connected to a SkyController's RTSP server but the
* SkyController itself is not yet connected to a drone. Similarly,
* when connected to a drone's stream through a SkyController's RTSP
* server, if the drone is disconnected from the SkyController, this
* function will be called with a 0 value in the ready parameter.
* @param pdraw: PDrAW instance handle
* @param demuxer: demuxer handle
* @param ready: 1 if the session is ready to play, 0 otherwise
* @param userdata: user data pointer */
void (*ready_to_play)(struct pdraw *pdraw,
struct pdraw_demuxer *demuxer,
int ready,
void *userdata);
/* End of range callback function, called when the playback is suspended
* after having reached the end of the playback duration (optional,
* can be null). This function is only called for replays (either local
* or streamed), not for live streams. The timestamp parameter is the
* current play time in microseconds at the moment the playback is
* suspended.
* @param pdraw: PDrAW instance handle
* @param demuxer: demuxer handle
* @param timestamp: current playback time in microseconds
* @param userdata: user data pointer */
void (*end_of_range)(struct pdraw *pdraw,
struct pdraw_demuxer *demuxer,
uint64_t timestamp,
void *userdata);
/* Play response callback function, called when a play operation is
* complete (the playback has started) or has failed (optional, can be
* null). The status parameter is the play operation status: 0 on
* success, or a negative errno value in case of error. The timestamp
* parameter is the current play time in microseconds at the moment the
* playback is started. The speed parameter is the current playback
* speed; a negative value means playing backward.
* @param pdraw: PDrAW instance handle
* @param demuxer: demuxer handle
* @param status: 0 on success, negative errno value in case of error
* @param timestamp: current playback time in microseconds
* @param speed: current playback speed, negative means backward
* @param userdata: user data pointer */
void (*play_resp)(struct pdraw *pdraw,
struct pdraw_demuxer *demuxer,
int status,
uint64_t timestamp,
float speed,
void *userdata);
/* Pause response callback function, called when a pause operation is
* complete (the playback is suspended) or has failed (optional, can be
* null). The status parameter is the pause operation status: 0 on
* success, or a negative errno value in case of error. The timestamp
* parameter is the current play time in microseconds at the moment the
* playback is paused.
* @param pdraw: PDrAW instance handle
* @param demuxer: demuxer handle
* @param status: 0 on success, negative errno value in case of error
* @param timestamp: current playback time in microseconds
* @param userdata: user data pointer */
void (*pause_resp)(struct pdraw *pdraw,
struct pdraw_demuxer *demuxer,
int status,
uint64_t timestamp,
void *userdata);
/* Seek response callback function, called when a seek operation is
* complete or has failed (optional, can be null).
* The status parameter is the seek operation status: 0 on success,
* or a negative errno value in case of error. The timestamp parameter
* is the current play time in microseconds after seeking. The speed
* parameter is the current playback speed; a negative value means
* playing backward.
* @param pdraw: PDrAW instance handle
* @param demuxer: demuxer handle
* @param status: 0 on success, negative errno value in case of error
* @param timestamp: current playback time in microseconds
* @param speed: current playback speed, negative means backward
* @param userdata: user data pointer */
void (*seek_resp)(struct pdraw *pdraw,
struct pdraw_demuxer *demuxer,
int status,
uint64_t timestamp,
float speed,
void *userdata);
};
/* Video renderer callback functions */
struct pdraw_video_renderer_cbs {
/* Media added callback function, called when a media has been added
* internally to the renderer. Medias are raw video medias.
* This function is called from the pomp_loop thread.
* @param pdraw: PDrAW instance handle
* @param renderer: renderer handle
* @param info: pointer on the media information
* @param userdata: user data pointer */
void (*media_added)(struct pdraw *pdraw,
struct pdraw_video_renderer *renderer,
const struct pdraw_media_info *info,
void *userdata);
/* Media removed callback function, called when a media has been removed
* internally from the renderer. Medias are raw video medias.
* This function is called from the pomp_loop thread.
* @param pdraw: PDrAW instance handle
* @param renderer: renderer handle
* @param info: pointer on the media information
* @param userdata: user data pointer */
void (*media_removed)(struct pdraw *pdraw,
struct pdraw_video_renderer *renderer,
const struct pdraw_media_info *info,
void *userdata);
/* Render ready callback function, called both when a new frame is
* ready for rendering and periodically (optional, can be null).
* This function is called from the pomp_loop thread.
* @param pdraw: PDrAW instance handle
* @param renderer: renderer handle
* @param userdata: user data pointer */
void (*render_ready)(struct pdraw *pdraw,
struct pdraw_video_renderer *renderer,
void *userdata);
/* External texture loading callback function (optional, can be null).
* This function is called before the rendering of the video frame in
* order to override the frame loading as a texture. This can be used
* to transform the video frames outside of PDrAW before resuming the
* rendering. This function is called from the rendering thread.
* @param pdraw: PDrAW instance handle
* @param renderer: renderer handle
* @param texture_width: texture width in pixels
* @param texture_height: texture height in pixels
* @param media_info: media information
* @param frame: frame information
* @param frame_userdata: frame user data buffer
* @param frame_userdata_len: frame user data buffer size in bytes
* @param userdata: user data pointer
* @return 0 on success, negative errno value in case of error */
int (*load_texture)(struct pdraw *pdraw,
struct pdraw_video_renderer *renderer,
unsigned int texture_width,
unsigned int texture_height,
const struct pdraw_media_info *media_info,
struct mbuf_raw_video_frame *frame,
const void *frame_userdata,
size_t frame_userdata_len,
void *userdata);
/* Overlay rendering callback function (optional, can be null).
* This function is called after the rendering of the video frame
* (if one is available) in order to render an application overlay
* on top of the video. When HMD distorsion correction is enabled
* in the renderer, it is applied after the overlay rendering.
* When no frame is available for the rendering, the frame_meta
* and frame_extra parameters are NULL. This function is called
* from the rendering thread.
* @param pdraw: PDrAW instance handle
* @param renderer: renderer handle
* @param render_pos: rendering position
* @param content_pos: video content position
* @param view_mat: 4x4 view matrix
* @param proj_mat: 4x4 projection matrix
* @param media_info: media information
* @param frame_meta: frame metadata (optional, can be NULL)
* @param frame_extra: frame extra information (optional, can be NULL)
* @param userdata: user data pointer */
void (*render_overlay)(
struct pdraw *pdraw,
struct pdraw_video_renderer *renderer,
const struct pdraw_rect *render_pos,
const struct pdraw_rect *content_pos,
const float *view_mat,
const float *proj_mat,
const struct pdraw_media_info *media_info,
struct vmeta_frame *frame_meta,
const struct pdraw_video_frame_extra *frame_extra,
void *userdata);
};
/* Coded video sink callback functions */
struct pdraw_coded_video_sink_cbs {
/* Coded video sink flush callback function, called when flushing is
* required (mandatory). When this function is called, the application
* must flush the sink queue by calling
* mbuf_coded_video_frame_queue_flush() and must return all frames
* outside of the queue by calling mbuf_coded_video_frame_unref(); once
* the flushing is done, the pdraw_coded_video_sink_queue_flushed()
* function must be called.
* @param pdraw: PDrAW instance handle
* @param sink: coded video sink handle
* @param userdata: user data pointer */
void (*flush)(struct pdraw *pdraw,
struct pdraw_coded_video_sink *sink,
void *userdata);
};
/* Raw video sink callback functions */
struct pdraw_raw_video_sink_cbs {
/* Raw video sink flush callback function, called when flushing is
* required (mandatory). When this function is called, the application
* must flush the sink queue by calling
* mbuf_raw_video_frame_queue_flush() and must return all frames outside
* of the queue by calling mbuf_raw_video_frame_unref(); once the
* flushing is done, the pdraw_raw_video_sink_queue_flushed() function
* must be called.
* @param pdraw: PDrAW instance handle
* @param sink: raw video sink handle
* @param userdata: user data pointer */
void (*flush)(struct pdraw *pdraw,
struct pdraw_raw_video_sink *sink,
void *userdata);
};
/**
* Instance management API
*/
/**
* Create a PDrAW instance.
* A running pomp_loop must be provided; all functions (with the exception of
* rendering functions) must be called from the pomp_loop thread; all callback
* functions (with the exception of rendering callbacks) are issued from the
* pomp_loop thread. The callbacks structure must be provided but all callback
* functions are optional. However, for correct management of the session it is
* highly recommended to implement at least the open_resp and close_resp
* functions. The instance handle is returned through the ret_obj parameter.
* When no longer needed, the instance must be freed using the pdraw_destroy()
* function. The pdraw_stop() function must be called and one must wait for the
* stop_resp callback function to be issued prior to calling pdraw_destroy().
* @param loop: pomp_loop to use
* @param cbs: PDrAW callback functions
* @param userdata: callback functions user data (optional, can be null)
* @param ret_obj: PDrAW instance handle (output)
* @return 0 on success, negative errno value in case of error
*/
PDRAW_API int pdraw_new(struct pomp_loop *loop,
const struct pdraw_cbs *cbs,
void *userdata,
struct pdraw **ret_obj);
/**
* Free a PDrAW instance.
* This function frees all resources associated with a PDrAW instance.
* If a successful pdraw_open_*() was made, the pdraw_close() function must
* be called and one must wait for the close_resp callback function to be
* issued prior to calling pdraw_destroy().
* @param pdraw: PDrAW instance handle
* @return 0 on success, negative errno value in case of error
*/
PDRAW_API int pdraw_destroy(struct pdraw *pdraw);
/**
* Stop a PDrAW instance.
* This function stops a PDrAW instance and all the associated objects.
* The function returns before the actual stopping is done. If the function
* returns 0, the stop_resp callback function will be called once the stopping
* is successful (0 status) or has failed (negative errno status). If the
* function returns a negative errno value (immediate failure), the stop_resp
* callback function will not be called. After a successful stop, the PDrAW
* instance must be destroyed by calling pdraw_destroy().
* @param pdraw: PDrAW instance handle
* @return 0 on success, negative errno value in case of error
*/
PDRAW_API int pdraw_stop(struct pdraw *pdraw);
/**
* Demuxer API
*/
/**
* Create a demuxer on a URL (stream or local file).
* The URL can be either an RTSP URL (starting with "rtsp://") or a local file
* path (either absolute or relative).
* The function returns before the actual opening is done. If the function
* returns 0, the open_resp callback function will be issued once the open
* operation is successful (0 status) or has failed (negative errno status).
* If the function returns a negative errno value (immediate failure), the
* open_resp callback function will not be issued.
* Once a demuxer is no longer used, it must be closed and then destroyed
* (@see the pdraw_demuxer_close() function).
* @param pdraw: PDrAW instance handle
* @param url: URL of the resource to open
* @param cbs: demuxer callback functions
* @param userdata: callback functions user data (optional, can be null)
* @param ret_obj: demuxer handle (output)
* @return 0 on success, negative errno value in case of error
*/
PDRAW_API int pdraw_demuxer_new_from_url(struct pdraw *pdraw,
const char *url,
const struct pdraw_demuxer_cbs *cbs,
void *userdata,
struct pdraw_demuxer **ret_obj);
/**
* Create a demuxer on a single stream.
* This function opens an RTP/AVP stream. No session management is done: it
* is the application's responsibility to handle the ports negociation with
* the sender. If null local ports are given as parameter, the effective port
* numbers used can be retrieved using the
* pdraw_get_single_stream_local_stream_port() for the RTP port and
* pdraw_get_single_stream_local_control_port() for the RTCP functions.
* If the local_addr parameter is left null, any local network interface will
* be used. The remote_addr, remote_stream_port and remote_control_port
* parameters can be left null if unknown; they will be known once the stream
* is being received.
* The function returns before the actual opening is done. If the function
* returns 0, the open_resp callback function will be issued once the open
* operation is successful (0 status) or has failed (negative errno status).
* If the function returns a negative errno value (immediate failure), the
* open_resp callback function will not be issued.
* Once a demuxer is no longer used, it must be closed and then destroyed
* (@see the pdraw_demuxer_close() function).
* @param pdraw: PDrAW instance handle
* @param local_addr: local IP address (optional, can be NULL)
* @param local_stream_port: local stream (RTP) port (optional, can be 0)
* @param local_control_port: local control (RTCP) port (optional, can be 0)
* @param remote_addr: remote IP address (optional, can be NULL)
* @param remote_stream_port: remote stream (RTP) port (optional, can be 0)
* @param remote_control_port: remote control (RTCP) port (optional, can be 0)
* @param cbs: demuxer callback functions
* @param userdata: callback functions user data (optional, can be null)
* @param ret_obj: demuxer handle (output)
* @return 0 on success, negative errno value in case of error
*/
PDRAW_API int
pdraw_demuxer_new_single_stream(struct pdraw *pdraw,
const char *local_addr,
uint16_t local_stream_port,
uint16_t local_control_port,
const char *remote_addr,
uint16_t remote_stream_port,
uint16_t remote_control_port,
const struct pdraw_demuxer_cbs *cbs,
void *userdata,
struct pdraw_demuxer **ret_obj);
/**
* Create a demuxer on a stream URL through a mux channel.
* The URL must be an RTSP URL (starting with "rtsp://"). Mux channels are used
* to transfer data between a SkyController remote and a smartphone through USB;
* see Parrot's libmux for more information.
* No concurrent sessions can run on the mux channel; therefore the user must
* take care of limiting the number of PDrAW instances and demuxer objects
* running on the mux channel to only one.
* The function returns before the actual opening is done. If the function
* returns 0, the open_resp callback function will be issued once the open
* operation is successful (0 status) or has failed (negative errno status).
* If the function returns a negative errno value (immediate failure), the
* open_resp callback function will not be issued.
* Once a demuxer is no longer used, it must be closed and then destroyed
* (@see the pdraw_demuxer_close() function).
* @param pdraw: PDrAW instance handle
* @param url: URL of the resource to open
* @param mux: mux instance handle
* @param cbs: demuxer callback functions
* @param userdata: callback functions user data (optional, can be null)
* @param ret_obj: demuxer handle (output)
* @return 0 on success, negative errno value in case of error
*/
PDRAW_API int
pdraw_demuxer_new_from_url_on_mux(struct pdraw *pdraw,
const char *url,
struct mux_ctx *mux,
const struct pdraw_demuxer_cbs *cbs,
void *userdata,
struct pdraw_demuxer **ret_obj);
/**
* Destroy a demuxer.
* This function stops a running demuxer and frees the associated resources.
* @param pdraw: PDrAW instance handle
* @param demuxer: demuxer handle
* @return 0 on success, negative errno value in case of error
*/
PDRAW_API int pdraw_demuxer_destroy(struct pdraw *pdraw,
struct pdraw_demuxer *demuxer);
/**
* Close a demuxer.
* This function closes a previously opened demuxer (either record or stream).
* The function returns before the actual closing is done. If the function
* returns 0, the close_resp callback function will be issued once the close is
* successful (0 status) or has failed (negative errno status). If the function
* returns a negative errno value (immediate failure), the close_resp callback
* function will not be issued. After a successful close, the demuxer must be
* destroyed by calling pdraw_demuxer_destroy().
* @param pdraw: PDrAW instance handle
* @param demuxer: demuxer handle
* @return 0 on success, negative errno value in case of error
*/
PDRAW_API int pdraw_demuxer_close(struct pdraw *pdraw,
struct pdraw_demuxer *demuxer);
/**
* Get the single stream local stream port.
* This function returns the local stream (RTP) port currently in use after
* a succesful open operation on a single stream (RTP/AVP) or an RTSP URL.
* If no open operation has been done, or if an open operation has been done
* on a mux channel, 0 is returned.
* This is useful when calling pdraw_open_single_stream() with null local
* ports to let PDrAW open sockets on any available port.
* @param pdraw: PDrAW instance handle
* @param demuxer: demuxer handle
* @return the stream port on success, 0 in case of error
*/
PDRAW_API uint16_t pdraw_demuxer_get_single_stream_local_stream_port(
struct pdraw *pdraw,
struct pdraw_demuxer *demuxer);
/**
* Get the single stream local control port.
* This function returns the local control (RTCP) port currently in use after
* a succesful open operation on a single stream (RTP/AVP) or an RTSP URL.
* If no open operation has been done, or if an open operation has been done
* on a mux channel, 0 is returned.
* This is useful when calling pdraw_open_single_stream() with null local
* ports to let PDrAW open sockets on any available port.
* @param pdraw: PDrAW instance handle
* @param demuxer: demuxer handle
* @return the stream port on success, 0 in case of error
*/
PDRAW_API uint16_t pdraw_demuxer_get_single_stream_local_control_port(
struct pdraw *pdraw,
struct pdraw_demuxer *demuxer);
/**
* Get the ready to play status.
* This function returns 1 if a successful open operation has been completed
* and if the playback is ready to start, 0 otherwise. One case when a
* successful open operation is complete but the playback is not ready is when
* connected to a SkyController's RTSP server but the SkyController itself is
* not yet connected to a drone.
* The value returned by this function is identical to the ready parameter
* passed to the ready_to_play callback function when it is issued.
* @param pdraw: PDrAW instance handle
* @param demuxer: demuxer handle
* @return the ready to play status on success, 0 in case of error
*/
PDRAW_API int pdraw_demuxer_is_ready_to_play(struct pdraw *pdraw,
struct pdraw_demuxer *demuxer);
/**
* Get the pause status.
* This function returns 1 if the playback is currently paused, 0 otherwise.
* @param pdraw: PDrAW instance handle
* @param demuxer: demuxer handle
* @return the pause status on success, 0 in case of error
*/
PDRAW_API int pdraw_demuxer_is_paused(struct pdraw *pdraw,
struct pdraw_demuxer *demuxer);
/**
* Play at normal speed (x1.0).
* This function starts the playback of the video.
* The function returns before the actual operation is done. If the function
* returns 0, the play_resp callback function will be issued once the play is
* successful (0 status) or has failed (negative errno status). If the function
* returns a negative errno value (immediate failure), the play_resp callback
* function will not be issued.
* @param pdraw: PDrAW instance handle
* @param demuxer: demuxer handle
* @return 0 on success, negative errno value in case of error
*/
PDRAW_API int pdraw_demuxer_play(struct pdraw *pdraw,
struct pdraw_demuxer *demuxer);
/**
* Play at the given speed.
* This function starts the playback of the video. If the speed parameter is
* negative, the video is played backward. If the speed is greater than or
* equal to PDRAW_PLAY_SPEED_MAX, the speed is ignored and the video is played
* at the maximum speed achievable. If the speed is less than or equal to
* -PDRAW_PLAY_SPEED_MAX, the speed is ignored and the video is played backward
* at the maximum speed achievable. A 0.0 speed has the same effet as calling
* the pdraw_pause() function. On a live stream, the speed parameter has
* no effect.
* The function returns before the actual operation is done. If the function
* returns 0, the play_resp callback function will be issued once the play is
* successful (0 status) or has failed (negative errno status). If the function
* returns a negative errno value (immediate failure), the play_resp callback
* function will not be issued.
* @param pdraw: PDrAW instance handle
* @param demuxer: demuxer handle
* @param speed: playback speed (0.0 means pause, negative value means
* play backward)
* @return 0 on success, negative errno value in case of error
*/
PDRAW_API int pdraw_demuxer_play_with_speed(struct pdraw *pdraw,
struct pdraw_demuxer *demuxer,
float speed);
/**
* Pause the playback.
* This function suspends the playback of the video. The session is not closed
* and the playback can be resumed using the play functions.
* The function returns before the actual operation is done. If the function
* returns 0, the pause_resp callback function will be issued once the pause is
* successful (0 status) or has failed (negative errno status). If the function
* returns a negative errno value (immediate failure), the pause_resp callback
* function will not be issued.
* @param pdraw: PDrAW instance handle
* @param demuxer: demuxer handle
* @return 0 on success, negative errno value in case of error
*/
PDRAW_API int pdraw_demuxer_pause(struct pdraw *pdraw,
struct pdraw_demuxer *demuxer);
/**
* Go to previous frame in frame-by-frame playback.
* This function plays the previous frame while the playback is paused. If the
* playback is not currently paused an error is returned. Frame-by-frame is
* only available on local replays (MP4 records).
* The function returns before the actual operation is done. If the function
* returns 0, the seek_resp callback function will be issued once the seek is
* successful (0 status) or has failed (negative errno status). If the function
* returns a negative errno value (immediate failure), the seek_resp callback
* function will not be issued.
* @param pdraw: PDrAW instance handle
* @param demuxer: demuxer handle
* @return 0 on success, negative errno value in case of error
*/
PDRAW_API int pdraw_demuxer_previous_frame(struct pdraw *pdraw,
struct pdraw_demuxer *demuxer);
/**
* Go to next frame in frame-by-frame playback.
* This function plays the next frame while the playback is paused. If the
* playback is not currently paused an error is returned. Frame-by-frame is
* only available on local replays (MP4 records).
* The function returns before the actual operation is done. If the function
* returns 0, the seek_resp callback function will be issued once the seek is
* successful (0 status) or has failed (negative errno status). If the function
* returns a negative errno value (immediate failure), the seek_resp callback
* function will not be issued.
* @param pdraw: PDrAW instance handle
* @param demuxer: demuxer handle
* @return 0 on success, negative errno value in case of error
*/
PDRAW_API int pdraw_demuxer_next_frame(struct pdraw *pdraw,
struct pdraw_demuxer *demuxer);
/**
* Seek forward or backward.
* This function seeks forward (positive delta) or backward (negative delta).
* The delta parameter is in microseconds. The exact parameter is a boolean
* value; when exact is 0 the seek is done to the nearest synchronization sample
* preceeding the delta, otherwise the seek is done to the sample nearest to the
* delta. Seeking is only available on replays (either local or streamed),
* not on live streams.
* The function returns before the actual operation is done. If the function
* returns 0, the seek_resp callback function will be issued once the seek is
* successful (0 status) or has failed (negative errno status). If the function
* returns a negative errno value (immediate failure), the seek_resp callback
* function will not be issued.
* @param pdraw: PDrAW instance handle
* @param demuxer: demuxer handle
* @param delta: time delta in microseconds (positive or negative)
* @param exact: 1 means seek to the sample closest to the delta, 0 means seek
* to the nearest synchronization sample preceeding the delta
* @return 0 on success, negative errno value in case of error
*/
PDRAW_API int pdraw_demuxer_seek(struct pdraw *pdraw,
struct pdraw_demuxer *demuxer,
int64_t delta,
int exact);
/**
* Seek forward.
* This function seeks forward by delta microseconds. It has the same
* behavior as calling pdraw_seek() with a positive delta. The exact parameter
* is a boolean value; when exact is 0 the seek is done to the nearest
* synchronization sample preceeding the delta, otherwise the seek is done to
* the sample nearest to the delta. Seeking is only available on replays
* (either local or streamed), not on live streams.
* The function returns before the actual operation is done. If the function
* returns 0, the seek_resp callback function will be issued once the seek is
* successful (0 status) or has failed (negative errno status). If the function
* returns a negative errno value (immediate failure), the seek_resp callback
* function will not be issued.
* @param pdraw: PDrAW instance handle
* @param demuxer: demuxer handle
* @param delta: positive time delta forward in microseconds
* @param exact: 1 means seek to the sample closest to the delta, 0 means seek
* to the nearest synchronization sample preceeding the delta
* @return 0 on success, negative errno value in case of error
*/
PDRAW_API int pdraw_demuxer_seek_forward(struct pdraw *pdraw,
struct pdraw_demuxer *demuxer,
uint64_t delta,
int exact);
/**
* Seek backward.
* This function seeks backward by delta microseconds (postive). It has the same
* behavior as calling pdraw_seek() with a negative delta. The exact parameter
* is a boolean value; when exact is 0 the seek is done to the nearest
* synchronization sample preceeding the delta, otherwise the seek is done to
* the sample nearest to the delta. Seeking is only available on replays
* (either local or streamed), not on live streams.
* The function returns before the actual operation is done. If the function
* returns 0, the seek_resp callback function will be issued once the seek is
* successful (0 status) or has failed (negative errno status). If the function
* returns a negative errno value (immediate failure), the seek_resp callback
* function will not be issued.
* @param pdraw: PDrAW instance handle
* @param demuxer: demuxer handle
* @param delta: positive time delta backward in microseconds
* @param exact: 1 means seek to the sample closest to the delta, 0 means seek
* to the nearest synchronization sample preceeding the delta
* @return 0 on success, negative errno value in case of error
*/
PDRAW_API int pdraw_demuxer_seek_back(struct pdraw *pdraw,
struct pdraw_demuxer *demuxer,
uint64_t delta,
int exact);
/**
* Seek to a given time.
* This function seeks to the given play timestamp in microseconds. The exact
* parameter is a boolean value; when exact is 0 the seek is done to the nearest
* synchronization sample preceeding the timestamp, otherwise the seek is done
* to the sample nearest to the timestamp. Seeking is only available on replays
* (either local or streamed), not on live streams.
* The function returns before the actual operation is done. If the function
* returns 0, the seek_resp callback function will be issued once the seek is
* successful (0 status) or has failed (negative errno status). If the function
* returns a negative errno value (immediate failure), the seek_resp callback
* function will not be issued.
* @param pdraw: PDrAW instance handle
* @param demuxer: demuxer handle
* @param timestamp: play timestamp in microseconds
* @param exact: 1 means seek to the sample closest to the timestamp,
* 0 means seek to the nearest synchronization sample
* preceeding the timestamp
* @return 0 on success, negative errno value in case of error
*/
PDRAW_API int pdraw_demuxer_seek_to(struct pdraw *pdraw,
struct pdraw_demuxer *demuxer,
uint64_t timestamp,
int exact);
/**
* Get the playback duration.
* This function returns the playback duration in microseconds. The duration is
* only available on replays (either local or streamed), not on live streams.
* @param pdraw: PDrAW instance handle
* @param demuxer: demuxer handle
* @return the duration in microseconds on success, 0 in case of error
*/
PDRAW_API uint64_t pdraw_demuxer_get_duration(struct pdraw *pdraw,
struct pdraw_demuxer *demuxer);
/**
* Get the playback current time.
* This function returns the current playback position in microseconds.
* On replays (either local or streamed) this is the position between 0 and
* the duration; on live streams this is the time since the start of the
* stream session.
* @param pdraw: PDrAW instance handle
* @param demuxer: demuxer handle
* @return the current time in microseconds on success, 0 in case of error
*/
PDRAW_API uint64_t
pdraw_demuxer_get_current_time(struct pdraw *pdraw,
struct pdraw_demuxer *demuxer);
/**
* Muxer API
*/
/**
* Create a muxer (experimental).
* This function creates a muxer with a given URL.
* Once the muxer is created medias can be added by id using the
* pdraw_muxer_add_media() function. Once a muxer is no longer used it must be
* destroyed by calling the pdraw_muxer_destroy() function. If writing to an
* MP4 file, the file is finalized in the pdraw_muxer_destroy() function.
* @note: experimental only, the function returns -ENOSYS
* @param pdraw: PDrAW instance handle
* @param url: destination URL
* @param ret_obj: muxer handle (output)
* @return 0 on success, negative errno value in case of error
*/
PDRAW_API int pdraw_muxer_new(struct pdraw *pdraw,
const char *url,
struct pdraw_muxer **ret_obj);
/**
* Destroy a muxer.
* This function stops a running muxer and frees the associated resources.
* @param pdraw: PDrAW instance handle
* @param muxer: muxer handle
* @return 0 on success, negative errno value in case of error
*/
PDRAW_API int pdraw_muxer_destroy(struct pdraw *pdraw,
struct pdraw_muxer *muxer);
/**
* Add a media to a muxer.
* This function adds a media to the muxer by its media_id. The media
* idenfifiers are known when the media_added or media_removed general
* callback functions are called.
* The params structure is only relevant for video medias; the structure must
* then be provided but all parameters are optional and can be left null.
* @param pdraw: PDrAW instance handle
* @param muxer: muxer handle
* @param media_id: identifier of the media to add to the muxer
* @param params: muxer video media parameters
* @return 0 on success, negative errno value in case of error
*/
PDRAW_API int
pdraw_muxer_add_media(struct pdraw *pdraw,
struct pdraw_muxer *muxer,
unsigned int media_id,
const struct pdraw_muxer_video_media_params *params);
/**
* Video renderer API
* @warning: all functions must be called from the application's
* rendering thread
*/
/**
* Create a video renderer.
* This function creates a video renderer on a media of the given media id;
* if the media id is zero the first raw media encountered is used.
* Once the renderer is created, the rendering is done by calling the
* pdraw_video_renderer_render*() functions. Once a renderer is no longer used
* it must be destroyed by calling the pdraw_video_renderer_destroy() function.
* The render_pos parameter sets the position and size of the rendering in the
* window/view; these coordinates are in pixels from the bottom-left corner
* (OpenGL coordinates). The params structure must be provided but all
* parameters are optional and can be left null.
* The callbacks structure must be provided but all callback functions are
* optional; all callback functions are called from the rendering thread,
* except the render_ready function which is called from the pomp_loop thread.
* @warning: this function must be called from the application's rendering
* thread.
* @param pdraw: PDrAW instance handle
* @param media_id: identifier of the raw media to render (from a
* pdraw_media_info structure); if zero the first
* raw media found is used for rendering
* @param render_pos: rendering position and size
* @param params: renderer parameters
* @param cbs: renderer callback functions
* @param userdata: callback functions user data (optional, can be null)
* @param ret_obj: renderer handle (output)
* @return 0 on success, negative errno value in case of error
*/
PDRAW_API int
pdraw_video_renderer_new(struct pdraw *pdraw,
unsigned int media_id,
const struct pdraw_rect *render_pos,
const struct pdraw_video_renderer_params *params,
const struct pdraw_video_renderer_cbs *cbs,
void *userdata,
struct pdraw_video_renderer **ret_obj);
/**
* Create a video renderer on an EGL display.
* This function creates a video renderer on an active EGL display context on a
* media of the given media id; if the media id is zero the first raw
* media encountered is used. Once the renderer is created, the rendering is
* done by calling the pdraw_video_renderer_render*() functions. Once a renderer
* is no longer used it must be destroyed by calling the
* pdraw_video_renderer_destroy() function. The render_pos parameter sets the
* position and size of the rendering in the window/view; these coordinates are
* in pixels from the bottom-left corner (OpenGL coordinates). The params
* structure must be provided but all parameters are optional and can be left
* null. The callbacks structure must be provided but all callback functions are
* optional; all callback functions are called from the rendering thread,
* except the render_ready function which is called from the pomp_loop thread.
* @warning: this function must be called from the application's rendering
* thread.
* @param pdraw: PDrAW instance handle
* @param media_id: identifier of the raw media to render (from a
* pdraw_media_info structure); if zero the first
* raw media found is used for rendering
* @param render_pos: rendering position and size
* @param params: renderer parameters
* @param cbs: renderer callback functions
* @param userdata: callback functions user data (optional, can be null)
* @param egl_display: EGL display context
* @param ret_obj: renderer handle (output)
* @return 0 on success, negative errno value in case of error
*/
PDRAW_API int
pdraw_video_renderer_new_egl(struct pdraw *pdraw,
unsigned int media_id,
const struct pdraw_rect *render_pos,
const struct pdraw_video_renderer_params *params,
const struct pdraw_video_renderer_cbs *cbs,
void *userdata,
struct egl_display *egl_display,
struct pdraw_video_renderer **ret_obj);
/**
* Destroy a video renderer.
* This function stops a running video renderer and frees the associated
* resources.
* @warning: this function must be called from the application's rendering
* thread.
* @param pdraw: PDrAW instance handle
* @param renderer: renderer handle
* @return 0 on success, negative errno value in case of error
*/
PDRAW_API int
pdraw_video_renderer_destroy(struct pdraw *pdraw,
struct pdraw_video_renderer *renderer);
/**
* Resize a video renderer.
* This function updates the rendering position on a running video renderer.
* The render_pos parameter sets the position and size of the rendering in the
* window/view; these coordinates are in pixels from the bottom-left corner
* (OpenGL coordinates).
* @warning: this function must be called from the application's rendering
* thread.
* @param pdraw: PDrAW instance handle
* @param renderer: renderer handle
* @param render_pos: rendering position and size
* @return 0 on success, negative errno value in case of error
*/
PDRAW_API int pdraw_video_renderer_resize(struct pdraw *pdraw,
struct pdraw_video_renderer *renderer,
const struct pdraw_rect *render_pos);
/**
* Set the video renderer media identifier.
* This function updates the identifier of the media on which the rendering is
* done; if the media id is zero the first raw media encountered is used.
* @warning: this function must be called from the application's rendering
* thread.
* @param pdraw: PDrAW instance handle
* @param renderer: renderer handle
* @param media_id: identifier of the raw media to render (from a
* pdraw_media_info structure); if zero the first raw media
* found is used for rendering
* @return 0 on success, negative errno value in case of error
*/
PDRAW_API int
pdraw_video_renderer_set_media_id(struct pdraw *pdraw,
struct pdraw_video_renderer *renderer,
unsigned int media_id);
/**
* Get the video renderer media identifier.
* This function retrieves the identifier of the media on which the rendering
* is done.
* @warning: this function must be called from the application's rendering
* thread.
* @param pdraw: PDrAW instance handle
* @param renderer: renderer handle
* @return the identifier of the media on success, 0 if no media is being
* renderered or in case of error
*/
PDRAW_API unsigned int
pdraw_video_renderer_get_media_id(struct pdraw *pdraw,
struct pdraw_video_renderer *renderer);
/**
* Set the video renderer parameters.
* This function updates the rendering parameters on a running video renderer.
* The params structure must be provided but all parameters are optional and
* can be left null.
* @warning: this function must be called from the application's rendering
* thread.
* @param pdraw: PDrAW instance handle
* @param renderer: renderer handle
* @param params: renderer parameters
* @return 0 on success, negative errno value in case of error
*/
PDRAW_API int pdraw_video_renderer_set_params(
struct pdraw *pdraw,
struct pdraw_video_renderer *renderer,
const struct pdraw_video_renderer_params *params);
/**
* Get the video renderer parameters.
* This function retrieves the rendering parameters on a running video renderer.
* The provided params structure is filled by the function.
* @warning: this function must be called from the application's rendering
* thread.
* @param pdraw: PDrAW instance handle
* @param renderer: renderer handle
* @param params: renderer parameters (output)
* @return 0 on success, negative errno value in case of error
*/
PDRAW_API int
pdraw_video_renderer_get_params(struct pdraw *pdraw,
struct pdraw_video_renderer *renderer,
struct pdraw_video_renderer_params *params);
/**
* Render the video.
* This function renders the video with the current rendering position and
* rendering parameters.
* For render-on-demand, consider using the render_ready callback function
* which is called both when a new frame is ready for rendering and
* periodically. Note that the render_ready callback function is called from
* the pomp_loop thread, not the rendering thread; the synchronization is up
* to the caller.
* If a content_pos structure is provided, it is filled with the actual position
* and size of the video within the rendering position; these coordinates are
* in pixels from the bottom-left corner (OpenGL coordinates).
* @warning: this function must be called from the application's rendering
* thread.
* @param pdraw: PDrAW instance handle
* @param renderer: renderer handle
* @param content_pos: video content position (output; optional, can be null)
* @return 0 on success, negative errno value in case of error
*/
PDRAW_API int pdraw_video_renderer_render(struct pdraw *pdraw,
struct pdraw_video_renderer *renderer,
struct pdraw_rect *content_pos);
/**
* Render the video with provided matrices.
* This function renders the video with the current rendering position and
* rendering parameters, and the provided view and projection matrices.
* The view_mat and proj_mat matrices are 4x4 OpenGL matrices.
* For render-on-demand, consider using the render_ready callback function
* which is called both when a new frame is ready for rendering and
* periodically. Note that the render_ready callback function is called from
* the pomp_loop thread, not the rendering thread; the synchronization is up
* to the caller.
* If a content_pos structure is provided, it is filled with the actual position
* and size of the video within the rendering position; these coordinates are
* in pixels from the bottom-left corner (OpenGL coordinates).
* @warning: this function must be called from the application's rendering
* thread.
* @param pdraw: PDrAW instance handle
* @param renderer: renderer handle
* @param content_pos: video content position (output; optional, can be null)
* @param view_mat: 4x4 view matrix
* @param proj_mat: 4x4 projection matrix
* @return 0 on success, negative errno value in case of error
*/
PDRAW_API int
pdraw_video_renderer_render_mat(struct pdraw *pdraw,
struct pdraw_video_renderer *renderer,
struct pdraw_rect *content_pos,
const float *view_mat,
const float *proj_mat);
/**
* Video sink API
*/
/**
* Create a coded video sink.
* This function creates a coded video sink on a media of the given media_id.
* The media idenfifiers are known when the media_added or media_removed
* general callback functions are called.
* Once the sink is created, video frames are retrieved by getting them
* from the queue returned by the pdraw_coded_video_sink_get_queue() function.
* Once a video sink is no longer used, it must be destroyed by calling the
* pdraw_coded_video_sink_destroy() function.
* The params structure must be provided but all parameters are optional and
* can be left null.
* The callbacks structure must be provided and the flush callback function is
* required to be implemented; all callback functions are called from the
* pomp_loop thread. When the flush callback function is called, the
* application must flush the sink queue by calling
* mbuf_coded_video_frame_queue_flush() and must return all frames outside of
* the queue by calling mbuf_coded_video_frame_unref(); once the flushing is
* complete, the pdraw_coded_video_sink_queue_flushed() function must be called.
*
* @note media_id must refer to a coded video media.
*
* @param pdraw: PDrAW instance handle
* @param media_id: identifier of the media on which to create the sink
* @param params: video sink parameters
* @param cbs: video sink callback functions
* @param userdata: callback functions user data (optional, can be null)
* @param ret_obj: video sink handle (output)
* @return 0 on success, negative errno value in case of error
*/
PDRAW_API int
pdraw_coded_video_sink_new(struct pdraw *pdraw,
unsigned int media_id,
const struct pdraw_video_sink_params *params,
const struct pdraw_coded_video_sink_cbs *cbs,
void *userdata,
struct pdraw_coded_video_sink **ret_obj);
/**
* Destroy a coded video sink.
* This function stops a running video sink and frees the associated resources.
* A video sink must not be destroyed unless all frames outside of the queue
* have been returned by calling mbuf_coded_video_frame_unref(). Once a video
* sink is destroyed the queue returned by pdraw_coded_video_sink_get_queue()
* must no longer be used.
* @param pdraw: PDrAW instance handle
* @param sink: video sink handle
* @return 0 on success, negative errno value in case of error
*/
PDRAW_API int
pdraw_coded_video_sink_destroy(struct pdraw *pdraw,
struct pdraw_coded_video_sink *sink);
/**
* Resynchronize a coded video sink.
* This function schedules the output of a synchronization frame (IDR) for a
* running video sink. It can be used for example in case of unrecoverable video
* decoder errors to restart decoding. After a video sink creation, the first
* frame that is output is always a synchronization frame; therefore it is not
* necessary to call this function immediately after a video sink creation.
* @param pdraw: PDrAW instance handle
* @param sink: video sink handle
* @return 0 on success, negative errno value in case of error
*/
PDRAW_API int
pdraw_coded_video_sink_resync(struct pdraw *pdraw,
struct pdraw_coded_video_sink *sink);
/**
* Get the coded video sink frame queue.
* This function returns the frame queue to use in order to retrieve frames
* from a running video sink. Frames are retrieved from the queue by using the
* mbuf_coded_video_frame_queue_pop() function.
* @param pdraw: PDrAW instance handle
* @param sink: video sink handle
* @return a pointer on a mbuf_coded_video_frame_queue object on success, NULL
* in case of error
*/
PDRAW_API struct mbuf_coded_video_frame_queue *
pdraw_coded_video_sink_get_queue(struct pdraw *pdraw,
struct pdraw_coded_video_sink *sink);
/**
* Signal that a coded video sink has been flushed.
* This function is used to signal that flushing is complete. When the flush
* video sink callback function is called, the application must flush the sink
* queue by calling mbuf_coded_video_frame_queue_flush() and must return all
* frames outside of the queue by calling mbuf_coded_video_frame_unref(); once
* the flushing is complete, this function must be called.
* @param pdraw: PDrAW instance handle
* @param sink: video sink handle
* @return 0 on success, negative errno value in case of error
*/
PDRAW_API int
pdraw_coded_video_sink_queue_flushed(struct pdraw *pdraw,
struct pdraw_coded_video_sink *sink);
/**
* Create a raw video sink.
* This function creates a raw video sink on a media of the given media_id.
* The media idenfifiers are known when the media_added or media_removed
* general callback functions are called.
* Once the sink is created, video frames are retrieved by getting them
* from the queue returned by the pdraw_raw_video_sink_get_queue() function.
* Once a video sink is no longer used, it must be destroyed by calling the
* pdraw_raw_video_sink_destroy() function.
* The params structure must be provided but all parameters are optional and
* can be left null.
* The callbacks structure must be provided and the flush callback function is
* required to be implemented; all callback functions are called from the
* pomp_loop thread. When the flush callback function is called, the
* application must flush the sink queue by calling
* mbuf_raw_video_frame_queue_flush() and must return all frames outside of
* the queue by calling mbuf_raw_video_frame_unref(); once the flushing is
* complete, the pdraw_raw_video_sink_queue_flushed() function must be called.
*
* @note media_id must refer to a raw video media.
*
* @param pdraw: PDrAW instance handle
* @param media_id: identifier of the media on which to create the sink
* @param params: video sink parameters
* @param cbs: video sink callback functions
* @param userdata: callback functions user data (optional, can be null)
* @param ret_obj: video sink handle (output)
* @return 0 on success, negative errno value in case of error
*/
PDRAW_API int
pdraw_raw_video_sink_new(struct pdraw *pdraw,
unsigned int media_id,
const struct pdraw_video_sink_params *params,
const struct pdraw_raw_video_sink_cbs *cbs,
void *userdata,
struct pdraw_raw_video_sink **ret_obj);
/**
* Destroy a raw video sink.
* This function stops a running video sink and frees the associated resources.
* A video sink must not be destroyed unless all frames outside of the queue
* have been returned by calling mbuf_raw_video_frame_unref(). Once a video
* sink is destroyed the queue returned by pdraw_raw_video_sink_get_queue() must
* no longer be used.
* @param pdraw: PDrAW instance handle
* @param sink: video sink handle
* @return 0 on success, negative errno value in case of error
*/
PDRAW_API int pdraw_raw_video_sink_destroy(struct pdraw *pdraw,
struct pdraw_raw_video_sink *sink);
/**
* Get the raw video sink frame queue.
* This function returns the frame queue to use in order to retrieve frames
* from a running video sink. Frames are retrieved from the queue by using the
* mbuf_raw_video_frame_queue_pop() function.
* @param pdraw: PDrAW instance handle
* @param sink: video sink handle
* @return a pointer on a mbuf_raw_video_frame_queue object on success, NULL
* in case of error
*/
PDRAW_API struct mbuf_raw_video_frame_queue *
pdraw_raw_video_sink_get_queue(struct pdraw *pdraw,
struct pdraw_raw_video_sink *sink);
/**
* Signal that a raw video sink has been flushed.
* This function is used to signal that flushing is complete. When the flush
* video sink callback function is called, the application must flush the sink
* queue by calling mbuf_raw_video_frame_queue_flush() and must return all
* frames outside of the queue by calling mbuf_raw_video_frame_unref(); once
* the flushing is complete, this function must be called.
* @param pdraw: PDrAW instance handle
* @param sink: video sink handle
* @return 0 on success, negative errno value in case of error
*/
PDRAW_API int
pdraw_raw_video_sink_queue_flushed(struct pdraw *pdraw,
struct pdraw_raw_video_sink *sink);
/**
* Settings API
*/
/**
* Get the PDrAW instance friendly name.
* This function fills the str array with the null-terminated friendly name.
* The string must have been previously allocated. The function writes up to
* len characters. The friendly name is generally either the device's friendly
* name (e.g. "Bob's phone") or the application's name (e.g.
* "MyDroneControllerApp"). It is used for example in metadata exchanged with a
* streaming server.
* @param pdraw: PDrAW instance handle
* @param str: pointer to the string to write to (output)
* @param len: maximum length of the string
* @return 0 on success, negative errno value in case of error
*/
PDRAW_API int
pdraw_get_friendly_name_setting(struct pdraw *pdraw, char *str, size_t len);
/**
* Set the PDrAW instance friendly name.
* The friendly_name string is copied internally. The friendly name is generally
* either the device's friendly name (e.g. "Bob's phone") or the application's
* name (e.g. "MyDroneControllerApp"). It is used for example in metadata
* exchanged with a streaming server. Setting the friendly name value is
* optional.
* @param pdraw: PDrAW instance handle
* @param friendly_name: pointer to the friendly name string
* @return 0 on success, negative errno value in case of error
*/
PDRAW_API int pdraw_set_friendly_name_setting(struct pdraw *pdraw,
const char *friendly_name);
/**
* Get the PDrAW instance serial number.
* This function fills the str array with the null-terminated serial number.
* The string must have been previously allocated. The function writes up to
* len characters. The serial number is generally the unique serial number of
* the device on which PDrAW is running. It is used for example in metadata
* exchanged with a streaming server.
* @param pdraw: PDrAW instance handle
* @param str: pointer to the string to write to (output)
* @param len: maximum length of the string
* @return 0 on success, negative errno value in case of error
*/
PDRAW_API int
pdraw_get_serial_number_setting(struct pdraw *pdraw, char *str, size_t len);
/**
* Set the PDrAW instance serial number.
* The serial_number string is copied internally. The serial number is generally
* the unique serial number of the device on which PDrAW is running. It is used
* for example in metadata exchanged with a streaming server. Setting the serial
* number value is recommended as it is used as a unique identifier in the
* streaming protocols.
* @param pdraw: PDrAW instance handle
* @param serial_number: pointer to the serial number string
* @return 0 on success, negative errno value in case of error
*/
PDRAW_API int pdraw_set_serial_number_setting(struct pdraw *pdraw,
const char *serial_number);
/**
* Get the PDrAW instance software version.
* This function fills the str array with the null-terminated software version.
* The string must have been previously allocated. The function writes up to
* len characters. The software version is generally the version number of the
* application running PDrAW (e.g. "MyApp v1.2.3"). It is used for example in
* metadata exchanged with a streaming server.
* @param pdraw: PDrAW instance handle
* @param str: pointer to the string to write to (output)
* @param len: maximum length of the string
* @return 0 on success, negative errno value in case of error
*/
PDRAW_API int
pdraw_get_software_version_setting(struct pdraw *pdraw, char *str, size_t len);
/**
* Set the PDrAW instance software version.
* The software_version string is copied internally. The software version is
* generally the version number of the application running PDrAW (e.g.
* "MyApp v1.2.3"). It is used for example in metadata exchanged with a
* streaming server. Setting the software version value is optional.
* @param pdraw: PDrAW instance handle
* @param software_version: pointer to the software version string
* @return 0 on success, negative errno value in case of error
*/
PDRAW_API int pdraw_set_software_version_setting(struct pdraw *pdraw,
const char *software_version);
/**
* Get the pipeline mode setting.
* This function returns the pipeline mode of a PDrAW instance. The pipeline
* mode controls whether to decode the selected video media (for full processing
* up to the rendering), or to disable video decoding (e.g. when no rendering
* is required, only a coded video sink).
* @param pdraw: PDrAW instance handle
* @return the pipeline mode, or PDRAW_PIPELINE_MODE_DECODE_ALL in case of error
*/
PDRAW_API enum pdraw_pipeline_mode
pdraw_get_pipeline_mode_setting(struct pdraw *pdraw);
/**
* Set the pipeline mode setting.
* This function sets the pipeline mode of a PDrAW instance. This function can
* be called only prior to any open operation. The pipeline mode controls
* whether to decode the selected video media (for full processing up to the
* rendering), or to disable video decoding (e.g. when no rendering is required,
* only an coded video sink).
* @param pdraw: PDrAW instance handle
* @param mode: pipeline mode
* @return 0 on success, negative errno value in case of error
*/
PDRAW_API int pdraw_set_pipeline_mode_setting(struct pdraw *pdraw,
enum pdraw_pipeline_mode mode);
/**
* Get the display screen settings.
* This function returns the display screen settings through the xdpi, ydpi and
* device_margin_* parameters. This is only useful if HMD distortion correction
* is enabled in the video rendering. The xdpi and ydpi are pixel densities in
* dots per inches. The device margins are in millimeters.
* @param pdraw: PDrAW instance handle
* @param xdpi: horizontal pixel density (output)
* @param ydpi: vertical pixel density (output)
* @param device_margin_top: top device margin (output)
* @param device_margin_bottom: bottom device margin (output)
* @param device_margin_left: left device margin (output)
* @param device_margin_right: right device margin (output)
* @return 0 on success, negative errno value in case of error
*/
PDRAW_API int pdraw_get_display_screen_settings(struct pdraw *pdraw,
float *xdpi,
float *ydpi,
float *device_margin_top,
float *device_margin_bottom,
float *device_margin_left,
float *device_margin_right);
/**
* Set the display screen settings.
* This function sets the display screen settings. This is only useful if HMD
* distortion correction is enabled in the video rendering. The xdpi and ydpi
* are pixel densities in dots per inches. The device margins are in
* millimeters.
* @param pdraw: PDrAW instance handle
* @param xdpi: horizontal pixel density
* @param ydpi: vertical pixel density
* @param device_margin_top: top device margin
* @param device_margin_bottom: bottom device margin
* @param device_margin_left: left device margin
* @param device_margin_right: right device margin
* @return 0 on success, negative errno value in case of error
*/
PDRAW_API int pdraw_set_display_screen_settings(struct pdraw *pdraw,
float xdpi,
float ydpi,
float device_margin_top,
float device_margin_bottom,
float device_margin_left,
float device_margin_right);
/**
* Get the HMD model setting.
* This function returns the head-mounted display (HMD) model. This is only
* useful if HMD distortion correction is enabled in the video rendering.
* @param pdraw: PDrAW instance handle
* @return the HMD model, or PDRAW_HMD_MODEL_UNKNOWN in case of error
*/
PDRAW_API enum pdraw_hmd_model pdraw_get_hmd_model_setting(struct pdraw *pdraw);
/**
* Set the HMD model setting.
* This function sets the head-mounted display (HMD) model. This is only
* useful if HMD distortion correction is enabled in the video rendering.
* @param pdraw: PDrAW instance handle
* @param hmd_model: HMD model
* @return 0 on success, negative errno value in case of error
*/
PDRAW_API int pdraw_set_hmd_model_setting(struct pdraw *pdraw,
enum pdraw_hmd_model hmd_model);
/**
* Platform-specific API
*/
/**
* Set the Android JVM pointer.
* This function sets the JVM pointer for internal calls to the Android SDK API.
* This is only useful on Android and is ignored on other platforms. If the
* JVM pointer is not provided on Android platforms, some features may not be
* available.
* @param pdraw: PDrAW instance handle
* @param jvm: JVM pointer
* @return 0 on success, negative errno value in case of error
*/
PDRAW_API int pdraw_set_android_jvm(struct pdraw *pdraw, void *jvm);
/**
* Debug API
*/
/**
* Dump the current pipeline as a directed graph using the DOT file format.
* @param pdraw: PDrAW instance handle
* @param file_name: DOT file to write to
* @return 0 on success, negative errno value in case of error
*/
PDRAW_API int pdraw_dump_pipeline(struct pdraw *pdraw, const char *file_name);
/**
* Helpers
*/
/**
* ToString function for enum pdraw_hmd_model.
* @param val: HMD model value to convert
* @return a string description of the HMD model
*/
PDRAW_API const char *pdraw_hmd_model_str(enum pdraw_hmd_model val);
/**
* ToString function for enum pdraw_pipeline_mode.
* @param val: pipeline mode value to convert
* @return a string description of the pipeline mode
*/
PDRAW_API const char *pdraw_pipeline_mode_str(enum pdraw_pipeline_mode val);
/**
* ToString function for enum pdraw_playback_type.
* @param val: playback type value to convert
* @return a string description of the playback type
*/
PDRAW_API const char *pdraw_playback_type_str(enum pdraw_playback_type val);
/**
* ToString function for enum pdraw_media_type.
* @param val: media type value to convert
* @return a string description of the media type
*/
PDRAW_API const char *pdraw_media_type_str(enum pdraw_media_type val);
/**
* ToString function for enum pdraw_video_type.
* @param val: video type value to convert
* @return a string description of the video type
*/
PDRAW_API const char *pdraw_video_type_str(enum pdraw_video_type val);
/**
* ToString function for enum pdraw_histogram_channel.
* @param val: histogram channel value to convert
* @return a string description of the histogram channel
*/
PDRAW_API const char *
pdraw_histogram_channel_str(enum pdraw_histogram_channel val);
/**
* ToString function for enum pdraw_video_renderer_scheduling_mode.
* @param val: video renderer scheduling mode value to convert
* @return a string description of the video renderer scheduling mode
*/
PDRAW_API const char *pdraw_video_renderer_scheduling_mode_str(
enum pdraw_video_renderer_scheduling_mode val);
/**
* ToString function for enum pdraw_video_renderer_fill_mode.
* @param val: video renderer fill mode value to convert
* @return a string description of the video renderer fill mode
*/
PDRAW_API const char *
pdraw_video_renderer_fill_mode_str(enum pdraw_video_renderer_fill_mode val);
/**
* ToString function for enum pdraw_video_renderer_transition_flag.
* @param val: video renderer transition flag value to convert
* @return a string description of the video renderer transition flag
*/
PDRAW_API const char *pdraw_video_renderer_transition_flag_str(
enum pdraw_video_renderer_transition_flag val);
/**
* Convert a video frame metadata structure to a JSON object.
* The JSON object must have been previously created. The function appends
* new elements in this object.
* @param frame: pointer to a video frame structure
* @param metadata: optional pointer to the frame metadata
* @param jobj: pointer to a JSON object to fill (output)
* @return 0 on success, negative errno value in case of error
*/
PDRAW_API int pdraw_video_frame_to_json(const struct pdraw_video_frame *frame,
struct vmeta_frame *metadata,
struct json_object *jobj);
/**
* Convert a video frame metadata structure to a JSON string.
* This function fills the str array with the null-terminated JSON string.
* The string must have been previously allocated. The function writes
* up to len characters.
* @param frame: pointer to a video frame structure
* @param metadata: optional pointer to the frame metadata
* @param str: pointer to the string to write to (output)
* @param len: maximum length of the string
* @return 0 on success, negative errno value in case of error
*/
PDRAW_API int
pdraw_video_frame_to_json_str(const struct pdraw_video_frame *frame,
struct vmeta_frame *metadata,
char *str,
unsigned int len);
/**
* Duplicate a media_info structure.
* @param src: pointer to the media_info structure to duplicate
* @return a pointer to the newly allocated structure or NULL on error.
*/
PDRAW_API struct pdraw_media_info *
pdraw_media_info_dup(const struct pdraw_media_info *src);
/**
* Free a media_info structure.
* @param media_info: pointer to the media_info structure to free
*/
PDRAW_API void pdraw_media_info_free(struct pdraw_media_info *media_info);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* !_PDRAW_H_ */