bsfeeder_buffer_impl.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #include <errno.h>
  5. #include "vpuapifunc.h"
  6. #include "main_helper.h"
  7. #define MAX_FEEDING_SIZE 0x400000 /* 4MBytes */
  8. #define DEFAULT_FEEDING_SIZE 0x20000 /* 128KBytes */
  9. typedef struct FeederFixedContext {
  10. void* address;
  11. Uint32 size;
  12. Uint32 offset;
  13. Uint32 feedingSize;
  14. BOOL eos;
  15. } FeederFixedContext;
  16. void* BSFeederBuffer_Create(
  17. const char* path,
  18. CodStd codecId
  19. )
  20. {
  21. FeederFixedContext* context=NULL;
  22. UNREFERENCED_PARAMETER(codecId);
  23. context = (FeederFixedContext*)osal_malloc(sizeof(FeederFixedContext));
  24. if (context == NULL) {
  25. VLOG(ERR, "%s:%d failed to allocate memory\n", __FUNCTION__, __LINE__);
  26. return NULL;
  27. }
  28. context->feedingSize = DEFAULT_FEEDING_SIZE;
  29. context->eos = FALSE;
  30. context->offset = 0;
  31. return (void*)context;
  32. }
  33. BOOL BSFeederBuffer_Destroy(
  34. void* feeder
  35. )
  36. {
  37. FeederFixedContext* context = (FeederFixedContext*)feeder;
  38. if (context == NULL) {
  39. VLOG(ERR, "%s:%d Null handle\n", __FUNCTION__, __LINE__);
  40. return FALSE;
  41. }
  42. osal_free(context);
  43. return TRUE;
  44. }
  45. void BSFeederBuffer_SetData(
  46. void* feeder,
  47. char* address,
  48. Uint32 size)
  49. {
  50. FeederFixedContext* context = (FeederFixedContext*)feeder;
  51. context->address = address;
  52. context->size = size;
  53. }
  54. void BSFeederBuffer_SetEos(void* feeder)
  55. {
  56. FeederFixedContext* context = (FeederFixedContext*)feeder;
  57. context->eos = TRUE;
  58. }
  59. BOOL BSFeederBuffer_GetEos(void* feeder)
  60. {
  61. FeederFixedContext* context = (FeederFixedContext*)feeder;
  62. return context->eos;
  63. }
  64. Int32 BSFeederBuffer_Act(
  65. void* feeder,
  66. BSChunk* chunk
  67. )
  68. {
  69. FeederFixedContext* context = (FeederFixedContext*)feeder;
  70. if (context == NULL) {
  71. VLOG(ERR, "%s:%d Null handle\n", __FUNCTION__, __LINE__);
  72. return 0;
  73. }
  74. // Due to memory performance, memset is temporarily commented
  75. // osal_memset(chunk->data, 0x00, chunk->size);
  76. if (context->size == 0) {
  77. chunk->eos = TRUE;
  78. return 0;
  79. }
  80. do {
  81. osal_memcpy(chunk->data, context->address, context->size);
  82. } while (FALSE);
  83. return context->size;
  84. }
  85. BOOL BSFeederBuffer_Rewind(
  86. void* feeder
  87. )
  88. {
  89. FeederFixedContext* context = (FeederFixedContext*)feeder;
  90. context->eos = FALSE;
  91. return TRUE;
  92. }
  93. void BSFeederBuffer_SetFeedingSize(
  94. void* feeder,
  95. Uint32 feedingSize
  96. )
  97. {
  98. FeederFixedContext* context = (FeederFixedContext*)feeder;
  99. if (feedingSize > 0) {
  100. context->feedingSize = feedingSize;
  101. }
  102. }