-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgleed.h
805 lines (730 loc) · 32.2 KB
/
gleed.h
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
/*
GleedSDL library
Version 1.0.0
Copyright (c) 2024-2025 Nikita Kogut
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef GLEED_H
#define GLEED_H
#include <SDL3/SDL.h>
#ifdef __cplusplus
extern "C"
{
#endif
/* Library version, mimics SDL defines*/
#define GLEED_MAJOR_VERSION 1
#define GLEED_MOVIE_MINOR_VERSION 0
#define GLEED_MOVIE_MICRO_VERSION 0
#define GLEED_VERSION \
SDL_VERSIONNUM(SDL_IMAGE_MAJOR_VERSION, SDL_IMAGE_MINOR_VERSION, SDL_IMAGE_MICRO_VERSION)
/**
* Maximum number of tracks in a single movie that GleedMovie can load
*/
#define MAX_GLEED_TRACKS 8
/**
* Constant to represent no track number
*/
#define GLEED_NO_TRACK -1
/**
* Movie track type
*/
typedef enum
{
GLEED_TRACK_TYPE_UNKNOWN = 0, /**< Unknown track, should not be used */
GLEED_TRACK_TYPE_VIDEO = 1, /**< Video track */
GLEED_TRACK_TYPE_AUDIO = 2, /**< Audio track */
} GleedMovieTrackType;
/**
* Movie codec type
*/
typedef enum
{
GLEED_CODEC_TYPE_UNKNOWN = 0, /**< Unknown codec, should not be used */
GLEED_CODEC_TYPE_VP8 = 1, /**< VP8 video codec */
GLEED_CODEC_TYPE_VP9 = 2, /**< VP9 video codec */
GLEED_CODEC_TYPE_VORBIS = 3, /**< Vorbis audio codec */
GLEED_CODEC_TYPE_OPUS = 4, /**< Opus audio codec */
} GleedMovieCodecType;
/**
* Movie structure
*
* Represents single opened and parsed .webm file.
*
* Movie can be created via GleedOpen or GleedOpenIO functions.
* It must be freed with GleedFreeMovie function after no longer needed.
*
* Gleed API allows loading WebM file and per-frame decoding, but nothing more.
*
* Opaque structure, do not modify its members directly.
*/
typedef struct GleedMovie GleedMovie;
/**
* Movie track structure
*
* WebM files are subset of Matroska files, which may contain any number of tracks,
* each representing different stream of data (video, audio, subtitles, etc.).
*
* Tracks are built of individual frames, which can be decoded and rendered (or played back).
* Tracks can be selected for playback with GleedSelectTrack function.
*
* This structure represents single track in the movie file.
* Please note, video_ members are only valid for video tracks,
* and audio_ members are only valid for audio tracks respectively.
*
* Most of fields are from Matroska spec: https://www.matroska.org/technical/elements.html
*
* Currently, only video and audio tracks are supported by the library - others are ignored.
*
* You may read the track properties, but do not modify them.
*/
typedef struct
{
char name[256]; /**< Track name, or 'Unknown' if it was not specified in the file */
char language[32]; /**< Track language, or 'eng' if it was not specified in the file */
char codec_id[32]; /**< Matroska Codec ID of the track */
Uint8 *codec_private_data; /**< Codec private data, if available. Currently used mostly by Vorbis */
Uint32 codec_private_size; /**< Size of the codec private data */
Uint64 codec_delay; /**< Codec delay, if available, in Matroska ticks */
Uint64 seek_pre_roll; /**< Seek pre-roll, if available, in Matroska ticks */
Uint32 track_number; /**< Track number in the WebM file (usually indexed from 1) */
GleedMovieTrackType type; /**< Track type (video or audio) */
Uint32 total_frames; /**< Total number of frames in the track */
Uint32 total_bytes; /**< Total number of bytes in the track */
bool lacing; /**< True if the track uses lacing */
Uint32 video_width; /**< Video frame width, non-zero only for video tracks */
Uint32 video_height; /**< Video frame height, non-zero only for video tracks */
double video_frame_rate; /**< Video frame rate, may not be specified in the file */
double audio_sample_frequency; /**< Audio sample frequency, non-zero only for audio tracks */
double audio_output_frequency; /**< Audio output frequency, non-zero only for audio tracks */
Uint32 audio_channels; /**< Number of audio channels, non-zero only for audio tracks */
Uint32 audio_bit_depth; /**< Audio bit depth, non-zero only for audio tracks */
} GleedMovieTrack;
/**
* Audio sample type
*/
typedef float GleedMovieAudioSample;
/**
* Open movie (.webm) file
*
* This function opens and parses single .webm file.
* After successful parse, it will automatically select first available video and/or audio tracks,
* allowing you to playback movie right away.
*
* \param file Path to .webm file
*
* \returns Pointer to prepared GleedMovie, or NULL on error. Call GleedGetError to get the error message.
*/
extern GleedMovie *GleedOpen(const char *file);
/**
* Open movie (.webm) file from SDL IO stream
*
* Follows the same rules as GleedOpen, but reads the file from an SDL IO stream.
* Under the hood, actually GleedOpen is a wrapper around this function.
*
* If you provide custom IO stream, make sure it is seekable and readable.
*
* \param io SDL IO stream for the .webm file
*
* \returns Pointer to prepared GleedMovie, or NULL on error. Call GleedGetError to get the error message.
*/
extern GleedMovie *GleedOpenIO(SDL_IOStream *io);
/**
* Free (release) a movie instance
*
* Must be called after you no longer need the movie instance to cleanup its resources, including all dynamic memory allocations.
*
* GleedMovie pointer is no longer valid after this call.
*
* \param movie GleedMovie instance to free
* \param closeio If true, will close the SDL IO stream associated with the movie
*/
extern void GleedFreeMovie(GleedMovie *movie, bool closeio);
/**
* Get a track from movie
*
* This function returns a pointer to the track structure of the movie, if you want to query its properties.
*
* \param movie GleedMovie instance
* \param index Track index
*
* \returns Pointer to the track structure, or NULL if track does not exist or index is out of bounds
*/
extern const GleedMovieTrack *GleedGetTrack(const GleedMovie *movie, int index);
/**
* Get the number of tracks in the movie (both video and audio)
*
* \param movie GleedMovie instance
*
* \returns Number of tracks in the movie, or 0 if there are no tracks or movie is invalid
*/
extern int GleedGetTrackCount(const GleedMovie *movie);
/**
* Select a movie track
*
* This function allows you to select a video or audio track to be used for playback on the movie.
* All further decoding will be performed on the selected track.
*
* At once, only one video and one audio track can be selected.
*
* Usually you won't need this to call this manually,
* as the first available video and audio tracks are selected automatically after opening the movie.
*
* Please note, that the passed track index is not the same as the track number in the movie file,
* as some tracks may be skipped (e.g. subtitles or ones which are not supported) - it is zero indexed.
*
* You can use GleedGetTrack and GleedGetTrackCount to query available tracks.
*
* It's recommended to call this function BEFORE decoding any frames, as some codecs are stateful and require
* continuous decoding.
*
* \param movie GleedMovie instance
* \param type Track type (video or audio)
* \param track Track index to select
*/
extern void GleedSelectTrack(GleedMovie *movie, GleedMovieTrackType type, int track);
/**
* Create a playback texture
*
* This is a helper function that creates a streaming texture for playback, capable of being drawn with SDL_Renderer.
* The texture must be freed by user with SDL_DestroyTexture when no longer needed.
* Playback texture is not attached or bound in anyway to the movie instance, so it can be used freely
* and independently from the movie.
* This also means that calling this function again will create a new texture, not update the existing one.
*
* Texture format is SDL_PIXELFORMAT_RGB24, SDL_TEXTUREACCESS_STREAMING access mode
* and the size is the same as the video frame size.
*
* Contents of the texture can be easily updated with GleedUpdatePlaybackTexture function.
*
* \param movie GleedMovie instance with configured video track
* \param renderer SDL_Renderer instance to create the texture for
*
* \returns SDL_Texture instance for playback, or NULL on error. Call GleedGetError to get the error message.
*/
extern SDL_Texture *GleedCreatePlaybackTexture(GleedMovie *movie, SDL_Renderer *renderer);
/**
* Update playback texture with the current video frame
*
* This function will upload current video frame pixel data to the playback texture.
* It does not perform any strict checks on the texture origin, so you may provide even
* your custom texture, but it must be compatible with the video format of the movie.
*
* During this operation, texture will be locked.
*
* A texture of different size may be provided, then default SDL blitting rules will be applied (basically stretching).
*
* This function will result in error if there is no decoded video frame available.
*
* \param movie GleedMovie instance with configured video track and decoded video frame
* \param texture SDL_Texture instance to update with video frame
*
* \returns True on success, false on error. Call GleedGetError to get the error message.
*/
extern bool GleedUpdatePlaybackTexture(GleedMovie *movie, SDL_Texture *texture);
/**
* Check if there is a next video frame available
*
* If there is, you may call GleedNextVideoFrame.
*
* \returns true if there is a next video frame available, false otherwise or if there is an error.
*/
extern bool GleedHasNextVideoFrame(GleedMovie *movie);
/**
* Decodes current video frame of the movie.
*
* You should call this function before getting the video frame surface or updating playback textures.
*
* After successful decode, you can get the video frame surface with GleedGetVideoFrameSurface.
* You should also call GleedNextVideoFrame to move to the next frame.
*
* \param movie GleedMovie instance with configured video track
* \return True on success, false on error. Call GleedGetError to get the error message.
*/
extern bool GleedDecodeVideoFrame(GleedMovie *movie);
/**
* Get the current video frame surface
*
* This function returns the current video frame surface, which contains the decoded video frame pixels,
* that you can use for rendering the video frame.
*
* Of course, you must decode a frame with GleedDecodeVideoFrame before calling this function.
*
* If you are using SDL_Renderer, you may use GleedCreatePlaybackTexture and GleedUpdatePlaybackTexture functions
* respectively to create and update a SDL_Texture for playback.
*
* The format of the surface is SDL_PIXELFORMAT_RGB24, and the size is the same as the video frame size.
*
* The surface will be modified by the next call to GleedDecodeVideoFrame.
*
* \param movie GleedMovie instance with configured video track and decoded video frame
* \return SDL_Surface instance with the video frame pixels, or NULL on error. Call GleedGetError to get the error message.
*/
extern const SDL_Surface *GleedGetVideoFrameSurface(GleedMovie *movie);
/**
* Move to the next video frame
*
* This function should be called after decoding the current video frame with GleedDecodeVideoFrame, and
* (optionally) rendering it's contents, although this is not required.
*
* After calling this function, you can check if there is a next video frame available with GleedHasNextVideoFrame.
*
* Calling this function when there are no more video frames left will have no effect.
*
* \param movie GleedMovie instance with configured video track
*/
extern void GleedNextVideoFrame(GleedMovie *movie);
/**
* Check if there is a next audio frame available
*
* Each audio frame may contain multiple encoded audio samples.
*
* If there is, you may call GleedNextAudioFrame.
*
* \returns true if there is a next audio frame available, false otherwise or if there is an error.
*/
extern bool GleedHasNextAudioFrame(GleedMovie *movie);
/**
* Decodes current audio frame of the movie.
*
* You should call this function before getting the audio samples.
* Movie should have an audio track selected.
*
* After successful decode, you can get the audio samples with GleedGetAudioSamples.
*
* You should also call GleedNextAudioFrame to move to the next frame.
*
* \param movie GleedMovie instance with configured audio track
* \return True on success, false on error. Call GleedGetError to get the error message.
*/
extern bool GleedDecodeAudioFrame(GleedMovie *movie);
/**
* Get the audio samples of the current audio frame
*
* This function returns a pointer to buffer of decoded PCM audio samples for current frame.
* The buffer is valid until the next call to GleedDecodeAudioFrame.
*
* You can directly queue the samples for playback via SDL_PutAudioStreamData into
* a SDL_AudioStream that has the correct spec, obtained from GleedGetAudioSpec - the
* samples buffer has interleaved format, supported by SDL audio.
*
* The size of the buffer in bytes is returned in the size parameter,
* and the number of per-channel samples is returned in the count parameter.
*
* On error, both size and count will be set to 0.
*
* \param movie GleedMovie instance with configured audio track and decoded audio frame
* \param size Pointer to store the size of the buffer in bytes, or NULL if not needed
* \param count Pointer to store the number of samples in the buffer, or NULL if not needed
*
* \returns Pointer to the buffer with audio samples, or NULL on error. Call GleedGetError to get the error message.
*/
extern const GleedMovieAudioSample *GleedGetAudioSamples(GleedMovie *movie, size_t *size, int *count);
/**
* Move to the next audio frame
*
* This function should be called after decoding the current audio frame with GleedDecodeAudioFrame.
*
* After calling this function, you can check if there is a next audio frame available with GleedHasNextAudioFrame.
*
* Calling this function when there are no more audio frames left will have no effect.
*
* \param movie GleedMovie instance with configured audio track
*/
extern void GleedNextAudioFrame(GleedMovie *movie);
/**
* Get audio specification of the movie
*
* This function returns the audio spec for the currently selected audio track in the movie.
* The resulting samples from GleedGetAudioSamples will follow this spec.
*
* You may pass this audio spec to SDL Audio functions to create a matching audio stream/device.
*
* If there is no audio track selected, it will return NULL.
*
* The returned pointer is valid until the movie is freed.
*
* \param movie GleedMovie instance
*/
extern const SDL_AudioSpec *GleedGetAudioSpec(GleedMovie *movie);
/**
* Seek to a specific frame in the movie
*
* This function allows you to seek to a specific video frame in the movie.
* The seek may be not precise, as it will seek to the nearest keyframe.
*
* If both audio and video tracks are present, it will seek to the nearest keyframe of the video track
* and sync the audio track to the video track.
*
* \param movie GleedMovie instance
* \param frame Frame number to seek to
*/
extern void GleedSeekFrame(GleedMovie *movie, Uint32 frame);
/**
* Get the last frame decode time in milliseconds
*
* This function returns the time in milliseconds it took to decode the last video frame,
* which you can use for benchmarking or performance monitoring.
*
* \param movie GleedMovie instance
*
* \returns Time in milliseconds, 0 if no frame was decoded yet or on error.
*/
extern Uint32 GleedGetLastFrameDecodeTime(GleedMovie *movie);
/**
* Get the total number of video frames in the movie
*
* \param movie GleedMovie instance
* \returns Total number of video frames in the movie, or 0 on error.
*/
extern Uint32 GleedGetTotalVideoFrames(GleedMovie *movie);
/**
* Get the current video frame number
*
* This number is incremented with each call to GleedNextVideoFrame.
*
* \param movie GleedMovie instance
* \returns Current video frame number, or 0 on error.
*/
extern Uint32 GleedGetCurrentFrame(GleedMovie *movie);
/**
* Get the video size of the movie
*
* This function returns the width and height of the video frames in the movie, in pixels.
* Movie must have a video track selected.
*
* If there is an error, width and height parameters will not be changed.
*
* \param movie GleedMovie instance
* \param w Pointer to store the width of the video frames, or NULL if not needed
* \param h Pointer to store the height of the video frames, or NULL if not needed
*/
extern void GleedGetVideoSize(GleedMovie *movie, int *w, int *h);
/**
* Get the error message
*
* This function returns the last error message that occurred during the last operation.
*
* Currently, error is not cleared after retrieval or successful operation.
*
* \returns Error message string, or NULL if there was no error.
*/
extern const char *GleedGetError();
/**
* Preload audio stream
*
* This function will load WHOLE audio stream into memory, so it can be played back without any delay.
* Take care when working with large audio tracks.
* You may estimate the memory footprint of doing so by looking at track->total_bytes and track->total_frames.
* It does not perform decoding, only loads the encoded audio data into memory.
* It will still need to seek and read each frame separately because of the nature of the Matroska/WebM blocks.
* As audio tracks are usually much smaller than video tracks, this function is usually safe to call,
* and probably even recommended for smooth playback.
*
* \param movie GleedMovie instance with configured audio track
* \returns True on success, false on error. Call GleedGetError to get the error message.
*
*/
extern bool GleedPreloadAudioStream(GleedMovie *movie);
/*
Movie player structure
GleedMoviePlayer is a high level abstraction over GleedMovie, which allows you to play back movies
with respect to audio and video synchronization, and provides easy to use API for playback control.
Movie player can be created with GleedCreatePlayer() and must be freed with GleedFreePlayer().
Opaque structure, do not modify its members directly.
*/
typedef struct GleedMoviePlayer GleedMoviePlayer;
/**
* This constant can be used to as second argument to GleedUpdatePlayer to
* let player decide the time delta automatically.
*/
#define GLEED_PLAYER_TIME_DELTA_AUTO -1
/**
* Create a player from an existing movie
*
* This function creates a player from an existing movie instance.
* It's strongly recommended to NOT modify the movie instance while the player is active,
* and instead use the player API.
*
* In order to advance the playback, you must call GleedUpdatePlayer with the time delta in milliseconds.
*
* Player must be freed with GleedFreePlayer before freeing the movie itself.
*
* \param mov GleedMovie instance
*
* \returns Pointer to the player instance, or NULL on error. Call GleedGetError to get the error message.
*/
extern GleedMoviePlayer *GleedCreatePlayer(GleedMovie *mov);
/**
* Create a player from path
*
* Helper method to create a player from a file path. See GleedCreatePlayer for more information.
*
* \param path Path to the .webm file
*
* \returns Pointer to the player instance, or NULL on error. Call GleedGetError to get the error message.
*/
extern GleedMoviePlayer *GleedCreatePlayerFromPath(const char *path);
/**
* Create a player from SDL IO stream
*
* Helper method to create a player from an SDL IO stream. See GleedCreatePlayer for more information.
*
* \param io SDL IO stream for the .webm file
*
* \returns Pointer to the player instance, or NULL on error. Call GleedGetError to get the error message.
*/
extern GleedMoviePlayer *GleedCreatePlayerFromIO(SDL_IOStream *io);
/**
* Set player audio output device
*
* You may set an audio device as an output for the player.
* This will automatically create an SDL_AudioStream under the hood with needed spec,
* attach it to the device,
* and all decoded audio samples will be queued into this stream.
*
* Please note, this function DOES NOT open the audio device for the stream,
* you must open it by yourself - therefore you cannot pass SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK
* to this function, it will result in an error.
*
* The frequency of the audio device does not matter, as all resampling will be handed by audio stream.
*
* If you want to stop audio output, you may pass 0 as the device id.
* This will destroy the audio stream (if it was present) and stop automatic audio output.
*
* \param player GleedMoviePlayer instance
* \param dev SDL_AudioDeviceID of the opened audio device to output audio to
*
* \returns True on success, false on error. Call GleedGetError to get the error message.
*/
extern bool GleedSetPlayerAudioOutput(GleedMoviePlayer *player, SDL_AudioDeviceID dev);
/**
* Set player video output texture
*
* This function will set the output texture for the player,
* which will be automatically updated with decoded frame pixels during player update.
*
* Here apply the sames rules as with GleedUpdatePlaybackTexture - the texture must be compatible with the video format.
*
* So it's strongly recommended to pass the texture created with GleedCreatePlaybackTexture here.
*
* You may pass NULL to disable automatic texture update.
*
* \param player GleedMoviePlayer instance
* \param texture SDL_Texture instance to update with video frame
*
* \returns True on success, false on error. Call GleedGetError to get the error message.
*/
extern bool GleedSetPlayerVideoOutputTexture(
GleedMoviePlayer *player,
SDL_Texture *texture);
/*
Enum for player update result
*/
typedef enum
{
GLEED_PLAYER_UPDATE_NONE = 0, /**< No update was performed */
GLEED_PLAYER_UPDATE_AUDIO = 1 << 1, /**< Audio samples were updated */
GLEED_PLAYER_UPDATE_VIDEO = 1 << 2, /**< Video frame was updated */
GLEED_PLAYER_UPDATE_ERROR = 1 << 3, /**< An error occurred during update */
} GleedMoviePlayerUpdateResult;
/**
* Update the player
*
* This function updates the player with the time delta in milliseconds and advances playback when possible.
*
* This means that it will:
*
* 1) Advance movie frames counters
* 2) Decode needed video and audio frames
* 3) If an output texture was set with GleedSetPlayerVideoOutputTexture - the texture will be updated with new video frame pixels.
* 4) If an audio output device was set with GleedSetPlayerAudioOutput - the audio samples will be queued into the audio stream.
*
* It's usually should be called in your application loop once per frame (your app's frame, not a movie one).
*
* If the player is paused or the movie ended, no updates will be performed.
*
* If you pass GLEED_PLAYER_TIME_DELTA_AUTO as the time delta, the player will decide the time delta automatically -
* by using SDL_GetTicks() and the last frame time it remembers.
*
* Player may queue more audio samples than needed for the current frame in order to have a buffer for smoother experience.
*
* Returned value is a bitmask of GleedMoviePlayerUpdateResult values. On error, only GLEED_PLAYER_UPDATE_ERROR will be set.
*
* \param player GleedMoviePlayer instance
* \param time_delta_ms Time delta in milliseconds since last frame, or GLEED_PLAYER_TIME_DELTA_AUTO to let player decide automatically
*
* \returns GleedMoviePlayerUpdateResult bitmask of the update result, or GLEED_PLAYER_UPDATE_ERROR on error. Call GleedGetError to get the error message.
*/
extern GleedMoviePlayerUpdateResult GleedUpdatePlayer(GleedMoviePlayer *player, int time_delta_ms);
/**
* Get the player audio samples
*
* This function is similar to GleedGetAudioSamples, returning a pointer to decoded interleaved PCM audio samples for the current frame.
*
* Please note, the buffer is only valid until the next call to GleedUpdatePlayer - the values may be overwritten after that.
*
* Samples can be directly passed to SDL_PutAudioStreamData.
*
* If you have set an audio output with GleedSetPlayerAudioOutput,
* the samples will be queued automatically and this function should not be called, as it will return 0 samples.
*
* \param player GleedMoviePlayer instance
* \param count Pointer to store the number of samples in the buffer, or NULL if not needed
*
* \returns Pointer to the buffer with audio samples, or NULL on error. Call GleedGetError to get the error message.
*/
extern const GleedMovieAudioSample *GleedGetPlayerAvailableAudioSamples(
GleedMoviePlayer *player,
int *count);
/**
* Get the player current video frame surface
*
* This function is similar to GleedGetVideoFrameSurface, returning the current video frame surface.
*
* Please note, the surface is only valid until the next call to GleedUpdatePlayer - the values may be overwritten after that.
*
* If you have set a video output with GleedSetPlayerVideoOutputTexture, the texture will be updated automatically with
* the contents of this surface and there is no need to call this function.
*
* The size of the surface is equal to movie's video track dimensions.
*
* You may use this function to get current video frame to render if you are not using SDL_Renderer directly.
*
* \param player GleedMoviePlayer instance
*
* \returns SDL_Surface instance with the video frame pixels, or NULL on error. Call GleedGetError to get the error message.
*/
extern const SDL_Surface *GleedGetPlayerCurrentVideoFrameSurface(
GleedMoviePlayer *player);
/**
* Pause the player
*
* This function will pause the player, stopping the playback until it is resumed.
*
* Calls to GleedUpdatePlayer will be basically no-op.
*
* \param player GleedMoviePlayer instance
*/
extern void GleedPausePlayer(GleedMoviePlayer *player);
/**
* Resume the player
*
* This function will resume the player, continuing the playback.
*
* \param player GleedMoviePlayer instance
*/
extern void GleedResumePlayer(GleedMoviePlayer *player);
/**
* Check if the player is paused
*
* \param player GleedMoviePlayer instance
*
* \returns True if the player is paused, false otherwise
*/
extern bool GleedIsPlayerPaused(GleedMoviePlayer *player);
/**
* Check if the player has finished playback
*
* Player will automatically stop when it reaches the end of the movie and there no more frames to decode.
*
* \param player GleedMoviePlayer instance
*
* \returns True if the player has finished playback, false otherwise
*/
extern bool GleedHasPlayerFinished(GleedMoviePlayer *player);
/**
* Get the player current time in seconds
*
* This function returns the current time of the player in seconds - amount of time since movie start.
*
* \param player GleedMoviePlayer instance
*
* \returns Current time in seconds, or 0.0 on error.
*/
extern float GleedGetPlayerCurrentTimeSeconds(GleedMoviePlayer *player);
/**
* Get the player current time in milliseconds
*
* This function returns the current time of the player in milliseconds - amount of time since movie start.
*
* \param player GleedMoviePlayer instance
*
* \returns Current time in milliseconds, or 0 on error.
*/
extern Uint64 GleedGetPlayerCurrentTime(GleedMoviePlayer *player);
/**
* Check if the player has audio enabled
*
* You can modify this with GleedSetPlayerAudioEnabled
*
* \param player GleedMoviePlayer instance
*
* \returns True if the player has audio enabled, false otherwise
*/
extern bool GleedIsPlayerAudioEnabled(GleedMoviePlayer *player);
/**
* Check if the player has video enabled
*
* You can modify this with GleedSetPlayerVideoEnabled
*
* \param player GleedMoviePlayer instance
*
* \returns True if the player has video enabled, false otherwise
*/
extern bool GleedIsPlayerVideoEnabled(GleedMoviePlayer *player);
/**
* Set player audio enabled
*
* This function allows you to enable or disable audio playback in the player.
*
* It's strongly recommended to call this function before first call to GleedUpdatePlayer,
* as this function disabled audio decoding and output completely.
*
* If the player has no audio track, this function will have no effect.
*
* \param player GleedMoviePlayer instance
* \param enabled True to enable audio playback, false to disable
*/
extern void GleedSetPlayerAudioEnabled(GleedMoviePlayer *player, bool enabled);
/**
* Set player video enabled
*
* This function allows you to enable or disable video playback in the player.
*
* It's strongly recommended to call this function before first call to GleedUpdatePlayer,
* as this function disabled video decoding and output completely.
*
* If the player has no video track, this function will have no effect.
*
* \param player GleedMoviePlayer instance
* \param enabled True to enable video playback, false to disable
*/
extern void GleedSetPlayerVideoEnabled(GleedMoviePlayer *player, bool enabled);
/**
* Free the player
*
* This function must be called when you no longer need the player instance.
*
* It will free all resources associated with the player, but NOT the movie instance attached to it.
*
* \param player GleedMoviePlayer instance
*/
extern void GleedFreePlayer(GleedMoviePlayer *player);
#ifdef __cplusplus
}
#endif
#endif