glue.c 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. Copyright (c) 2024 Bruce A Henderson
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */
  19. #define PL_MPEG_IMPLEMENTATION
  20. #include "pl_mpeg.h"
  21. #include "brl.mod/blitz.mod/blitz.h"
  22. // #define PLM_BUFFER_MODE_STREAM 5
  23. extern void video_mpeg1_TMpeg1__VideoCallback(BBObject * obj, plm_frame_t * buffer);
  24. extern void video_mpeg1_TMpeg1__AudioCallback(BBObject * obj, plm_samples_t * samples);
  25. extern void video_mpeg1_TMpeg1__LoadCallback(BBObject * obj, plm_buffer_t * buffer);
  26. extern void video_mpeg1_TMpeg1__SeekCallback(BBObject * obj, plm_buffer_t * buffer, size_t offset);
  27. void bmx_mpeg1_load_callback(plm_buffer_t * buffer, void * data) {
  28. video_mpeg1_TMpeg1__LoadCallback((BBObject*)data, buffer);
  29. }
  30. void bmx_mpeg1_seek_callback(plm_buffer_t * buffer, size_t offset, void * data) {
  31. video_mpeg1_TMpeg1__SeekCallback((BBObject*)data, buffer, offset);
  32. }
  33. void bmx_mpeg1_video_callback(plm_t *player, plm_frame_t *frame, void *user) {
  34. video_mpeg1_TMpeg1__VideoCallback((BBObject*)user, frame);
  35. }
  36. void bmx_mpeg1_audio_callback(plm_t *player, plm_samples_t *samples, void *user) {
  37. video_mpeg1_TMpeg1__AudioCallback((BBObject*)user, samples);
  38. }
  39. plm_buffer_t * bmx_mpeg1_create_buffer(BBObject * obj, size_t size) {
  40. plm_buffer_t * buffer = plm_buffer_create_with_capacity(PLM_BUFFER_DEFAULT_SIZE);
  41. buffer->close_when_done = 0;
  42. buffer->mode = PLM_BUFFER_MODE_STREAM;
  43. buffer->discard_read_bytes = TRUE;
  44. buffer->total_size = size;
  45. plm_buffer_set_load_callback(buffer, bmx_mpeg1_load_callback, obj);
  46. plm_buffer_set_seek_callback(buffer, bmx_mpeg1_seek_callback, obj);
  47. return buffer;
  48. };
  49. plm_t * bmx_mpeg1_create(BBObject * obj, plm_buffer_t *buffer, int destroy_when_done) {
  50. plm_t * plm = plm_create_with_buffer(buffer, destroy_when_done);
  51. plm_set_video_decode_callback(plm, bmx_mpeg1_video_callback, obj);
  52. plm_set_audio_decode_callback(plm, bmx_mpeg1_audio_callback, obj);
  53. return plm;
  54. }
  55. void bmx_mpeg1_destroy(plm_t * plm) {
  56. plm_destroy(plm);
  57. }
  58. void bmx_plm_frame_to_rgba(plm_frame_t *frame, uint8_t *dest, int stride, int fillAlpha, int capacity) {
  59. if (fillAlpha) {
  60. memset(dest, 255, capacity);
  61. }
  62. plm_frame_to_rgba(frame, dest, stride);
  63. }