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.

129 lines
3.6KB

  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. /* initialize avpkt */
  55. av_init_packet(avpkt);
  56. /* set values for avpkt */
  57. avpkt->pts = 17;
  58. avpkt->dts = 2;
  59. avpkt->data = (uint8_t*)data;
  60. avpkt->size = strlen(data);
  61. avpkt->flags = AV_PKT_FLAG_DISCARD;
  62. avpkt->duration = 100;
  63. avpkt->pos = 3;
  64. ret = setup_side_data_entry(avpkt);
  65. return ret;
  66. }
  67. int main(void)
  68. {
  69. AVPacket avpkt;
  70. AVPacket *avpkt_clone = NULL;
  71. int ret = 0;
  72. if(initializations(&avpkt) < 0){
  73. printf("failed to initialize variables\n");
  74. return 1;
  75. }
  76. /* test av_packet_clone*/
  77. avpkt_clone = av_packet_clone(&avpkt);
  78. if(!avpkt_clone) {
  79. av_log(NULL, AV_LOG_ERROR,"av_packet_clone failed to clone AVPacket\n");
  80. return 1;
  81. }
  82. /*test av_grow_packet*/
  83. if(av_grow_packet(avpkt_clone, 20) < 0){
  84. av_log(NULL, AV_LOG_ERROR, "av_grow_packet failed\n");
  85. return 1;
  86. }
  87. if(av_grow_packet(avpkt_clone, INT_MAX) == 0){
  88. printf( "av_grow_packet failed to return error "
  89. "when \"grow_by\" parameter is too large.\n" );
  90. ret = 1;
  91. }
  92. /* test size error check in av_new_packet*/
  93. if(av_new_packet(avpkt_clone, INT_MAX) == 0){
  94. printf( "av_new_packet failed to return error "
  95. "when \"size\" parameter is too large.\n" );
  96. ret = 1;
  97. }
  98. /*test size error check in av_packet_from_data*/
  99. if(av_packet_from_data(avpkt_clone, avpkt_clone->data, INT_MAX) == 0){
  100. printf("av_packet_from_data failed to return error "
  101. "when \"size\" parameter is too large.\n" );
  102. ret = 1;
  103. }
  104. /*clean up*/
  105. av_packet_free(&avpkt_clone);
  106. av_packet_unref(&avpkt);
  107. return ret;
  108. }