You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

134 lines
3.7KB

  1. /*
  2. * This file is part of FFmpeg.
  3. *
  4. * FFmpeg is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * FFmpeg is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with FFmpeg; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <inttypes.h>
  21. #include <string.h>
  22. #include "libavcodec/avcodec.h"
  23. #include "libavutil/error.h"
  24. static int setup_side_data_entry(AVPacket* avpkt)
  25. {
  26. const uint8_t *data_name = NULL;
  27. int ret = 0, bytes;
  28. uint8_t *extra_data = NULL;
  29. /* get side_data_name string */
  30. data_name = av_packet_side_data_name(AV_PKT_DATA_NEW_EXTRADATA);
  31. /* Allocate a memory bloc */
  32. bytes = strlen(data_name);
  33. if(!(extra_data = av_malloc(bytes))){
  34. ret = AVERROR(ENOMEM);
  35. fprintf(stderr, "Error occurred: %s\n", av_err2str(ret));
  36. exit(1);
  37. }
  38. /* copy side_data_name to extra_data array */
  39. memcpy(extra_data, data_name, bytes);
  40. /* create side data for AVPacket */
  41. ret = av_packet_add_side_data(avpkt, AV_PKT_DATA_NEW_EXTRADATA,
  42. extra_data, bytes);
  43. if(ret < 0){
  44. fprintf(stderr,
  45. "Error occurred in av_packet_add_side_data: %s\n",
  46. av_err2str(ret));
  47. }
  48. return ret;
  49. }
  50. static int initializations(AVPacket* avpkt)
  51. {
  52. const static uint8_t* data = "selftest for av_packet_clone(...)";
  53. int ret = 0;
  54. /* set values for avpkt */
  55. avpkt->pts = 17;
  56. avpkt->dts = 2;
  57. avpkt->data = (uint8_t*)data;
  58. avpkt->size = strlen(data);
  59. avpkt->flags = AV_PKT_FLAG_DISCARD;
  60. avpkt->duration = 100;
  61. avpkt->pos = 3;
  62. ret = setup_side_data_entry(avpkt);
  63. return ret;
  64. }
  65. int main(void)
  66. {
  67. AVPacket *avpkt = NULL;
  68. AVPacket *avpkt_clone = NULL;
  69. int ret = 0;
  70. /* test av_packet_alloc */
  71. avpkt = av_packet_alloc();
  72. if(!avpkt) {
  73. av_log(NULL, AV_LOG_ERROR, "av_packet_alloc failed to allcoate AVPacket\n");
  74. return 1;
  75. }
  76. if (initializations(avpkt) < 0) {
  77. printf("failed to initialize variables\n");
  78. av_packet_free(&avpkt);
  79. return 1;
  80. }
  81. /* test av_packet_clone*/
  82. avpkt_clone = av_packet_clone(avpkt);
  83. if(!avpkt_clone) {
  84. av_log(NULL, AV_LOG_ERROR,"av_packet_clone failed to clone AVPacket\n");
  85. return 1;
  86. }
  87. /*test av_grow_packet*/
  88. if(av_grow_packet(avpkt_clone, 20) < 0){
  89. av_log(NULL, AV_LOG_ERROR, "av_grow_packet failed\n");
  90. return 1;
  91. }
  92. if(av_grow_packet(avpkt_clone, INT_MAX) == 0){
  93. printf( "av_grow_packet failed to return error "
  94. "when \"grow_by\" parameter is too large.\n" );
  95. ret = 1;
  96. }
  97. /* test size error check in av_new_packet*/
  98. if(av_new_packet(avpkt_clone, INT_MAX) == 0){
  99. printf( "av_new_packet failed to return error "
  100. "when \"size\" parameter is too large.\n" );
  101. ret = 1;
  102. }
  103. /*test size error check in av_packet_from_data*/
  104. if(av_packet_from_data(avpkt_clone, avpkt_clone->data, INT_MAX) == 0){
  105. printf("av_packet_from_data failed to return error "
  106. "when \"size\" parameter is too large.\n" );
  107. ret = 1;
  108. }
  109. /*clean up*/
  110. av_packet_free(&avpkt_clone);
  111. av_packet_free(&avpkt);
  112. return ret;
  113. }