meminput.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #include "global.h"
  2. #include "meminput.h"
  3. void malloc_mem_input(VideoParameters *p_Vid)
  4. {
  5. if ( (p_Vid->mem_input = (memory_input_t *) calloc(1, sizeof(memory_input_t))) == NULL)
  6. {
  7. snprintf(errortext, ET_SIZE, "Memory allocation for memory input failed");
  8. error(errortext,100);
  9. }
  10. }
  11. void free_mem_input(VideoParameters *p_Vid)
  12. {
  13. free(p_Vid->mem_input);
  14. p_Vid->mem_input = NULL;
  15. }
  16. /*!
  17. ************************************************************************
  18. * \brief
  19. * returns a byte from IO buffer
  20. ************************************************************************
  21. */
  22. static inline uint8_t getfbyte(memory_input_t *mem_input)
  23. {
  24. return mem_input->user_buffer[mem_input->user_buffer_read++];
  25. }
  26. /*!
  27. ************************************************************************
  28. * \brief
  29. * returns if new start code is found at byte aligned position buf.
  30. * new-startcode is of form N 0x00 bytes, followed by a 0x01 byte.
  31. *
  32. * \return
  33. * 1 if start-code is found or \n
  34. * 0, indicating that there is no start code
  35. *
  36. * \param Buf
  37. * pointer to byte-stream
  38. * \param zeros_in_startcode
  39. * indicates number of 0x00 bytes in start-code.
  40. ************************************************************************
  41. */
  42. static inline int FindStartCode (unsigned char *Buf, int zeros_in_startcode)
  43. {
  44. int i;
  45. for (i = 0; i < zeros_in_startcode; i++)
  46. {
  47. if(*(Buf++) != 0)
  48. {
  49. return 0;
  50. }
  51. }
  52. if(*Buf != 1)
  53. return 0;
  54. return 1;
  55. }
  56. /*!
  57. ************************************************************************
  58. * \brief
  59. * Returns the size of the NALU (bits between start codes in case of
  60. * Annex B. nalu->buf and nalu->len are filled. Other field in
  61. * nalu-> remain uninitialized (will be taken care of by NALUtoRBSP.
  62. *
  63. * \return
  64. * 0 if there is nothing any more to read (EOF)
  65. * -1 in case of any error
  66. *
  67. * \note Side-effect: Returns length of start-code in bytes.
  68. *
  69. * \note
  70. * GetAnnexbNALU expects start codes at byte aligned positions in the file
  71. *
  72. ************************************************************************
  73. */
  74. int GetMemoryNALU (VideoParameters *p_Vid, NALU_t *nalu)
  75. {
  76. memory_input_t *mem_input = p_Vid->mem_input;
  77. if (!mem_input->user_buffer)
  78. return 0;
  79. nalu->len = mem_input->user_buffer_size;
  80. memcpy(nalu->buf, mem_input->user_buffer, nalu->len);
  81. memzero16(nalu->buf+nalu->len); // add some extra 0's to the end
  82. nalu->forbidden_bit = (*(nalu->buf) >> 7) & 1;
  83. nalu->nal_reference_idc = (NalRefIdc) ((*(nalu->buf) >> 5) & 3);
  84. nalu->nal_unit_type = (NaluType) ((*(nalu->buf)) & 0x1f);
  85. nalu->lost_packets = 0;
  86. mem_input->user_buffer = 0;
  87. if (mem_input->skip_b_frames && nalu->nal_reference_idc == NALU_PRIORITY_DISPOSABLE)
  88. return 0;
  89. if (mem_input->resetting && nalu->nal_unit_type != NALU_TYPE_IDR)
  90. return 0;
  91. mem_input->resetting = 0;
  92. return 1;
  93. }
  94. /*!
  95. ************************************************************************
  96. * \brief
  97. * Opens the bit stream file named fn
  98. * \return
  99. * none
  100. ************************************************************************
  101. */
  102. void OpenMemory(VideoParameters *p_Vid, const char *fn)
  103. {
  104. memory_input_t *mem_input = p_Vid->mem_input;
  105. }
  106. /*!
  107. ************************************************************************
  108. * \brief
  109. * Closes the bit stream file
  110. ************************************************************************
  111. */
  112. void CloseMemory(VideoParameters *p_Vid)
  113. {
  114. memory_input_t *mem_input = p_Vid->mem_input;
  115. }