* commit 'a9a60106370f862e191dea58e748626da6a8fe97': avpacket: Provide an alloc and a free function for the struct
Unified · Split
| @@ -20,6 +20,8 @@ API changes, most recent first: · 19 unmodified lines | |||
| 20 | it resets the packet in a more consistent way. | 20 | it resets the packet in a more consistent way. |
| 21 | xxxxxx - Deprecate av_dup_packet(), it is a no-op for most cases. | 21 | xxxxxx - Deprecate av_dup_packet(), it is a no-op for most cases. |
| 22 | Use av_packet_ref() to make a non-refcounted AVPacket refcounted. | 22 | Use av_packet_ref() to make a non-refcounted AVPacket refcounted. |
| 23 | xxxxxx - Add av_packet_alloc(), av_packet_clone(), av_packet_free(). | ||
| 24 | They match the AVFrame functions with the same name. | ||
| 23 | 25 | ||
| 24 | 2015-10-27 - xxxxxxx - lavu 55.5.100 - cpu.h | 26 | 2015-10-27 - xxxxxxx - lavu 55.5.100 - cpu.h |
| 25 | Add AV_CPU_FLAG_AESNI. | 27 | Add AV_CPU_FLAG_AESNI. |
| @@ -3847,6 +3847,40 @@ void avsubtitle_free(AVSubtitle *sub); · 3846 unmodified lines | |||
| 3847 | * @{ | 3847 | * @{ |
| 3848 | */ | 3848 | */ |
| 3849 | 3849 | ||
| 3850 | /** | ||
| 3851 | * Allocate an AVPacket and set its fields to default values. The resulting | ||
| 3852 | * struct must be freed using av_packet_free(). | ||
| 3853 | * | ||
| 3854 | * @return An AVPacket filled with default values or NULL on failure. | ||
| 3855 | * | ||
| 3856 | * @note this only allocates the AVPacket itself, not the data buffers. Those | ||
| 3857 | * must be allocated through other means such as av_new_packet. | ||
| 3858 | * | ||
| 3859 | * @see av_new_packet | ||
| 3860 | */ | ||
| 3861 | AVPacket *av_packet_alloc(void); | ||
| 3862 | |||
| 3863 | /** | ||
| 3864 | * Create a new packet that references the same data as src. | ||
| 3865 | * | ||
| 3866 | * This is a shortcut for av_packet_alloc()+av_packet_ref(). | ||
| 3867 | * | ||
| 3868 | * @return newly created AVPacket on success, NULL on error. | ||
| 3869 | * | ||
| 3870 | * @see av_packet_alloc | ||
| 3871 | * @see av_packet_ref | ||
| 3872 | */ | ||
| 3873 | AVPacket *av_packet_clone(AVPacket *src); | ||
| 3874 | |||
| 3875 | /** | ||
| 3876 | * Free the packet, if the packet is reference counted, it will be | ||
| 3877 | * unreferenced first. | ||
| 3878 | * | ||
| 3879 | * @param packet packet to be freed. The pointer will be set to NULL. | ||
| 3880 | * @note passing NULL is a no-op. | ||
| 3881 | */ | ||
| 3882 | void av_packet_free(AVPacket **pkt); | ||
| 3883 | |||
| 3850 | /** | 3884 | /** |
| 3851 | * Initialize optional fields of a packet with default values. | 3885 | * Initialize optional fields of a packet with default values. |
| 3852 | * | 3886 | * |
| @@ -48,6 +48,26 @@ FF_ENABLE_DEPRECATION_WARNINGS · 47 unmodified lines | |||
| 48 | pkt->side_data_elems = 0; | 48 | pkt->side_data_elems = 0; |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | AVPacket *av_packet_alloc(void) | ||
| 52 | { | ||
| 53 | AVPacket *pkt = av_mallocz(sizeof(AVPacket)); | ||
| 54 | if (!pkt) | ||
| 55 | return pkt; | ||
| 56 | |||
| 57 | av_packet_unref(pkt); | ||
| 58 | |||
| 59 | return pkt; | ||
| 60 | } | ||
| 61 | |||
| 62 | void av_packet_free(AVPacket **pkt) | ||
| 63 | { | ||
| 64 | if (!pkt || !*pkt) | ||
| 65 | return; | ||
| 66 | |||
| 67 | av_packet_unref(*pkt); | ||
| 68 | av_freep(pkt); | ||
| 69 | } | ||
| 70 | |||
| 51 | static int packet_alloc(AVBufferRef **buf, int size) | 71 | static int packet_alloc(AVBufferRef **buf, int size) |
| 52 | { | 72 | { |
| 53 | int ret; | 73 | int ret; |
| @@ -542,6 +562,19 @@ fail: · 488 unmodified lines | |||
| 542 | return ret; | 562 | return ret; |
| 543 | } | 563 | } |
| 544 | 564 | ||
| 565 | AVPacket *av_packet_clone(AVPacket *src) | ||
| 566 | { | ||
| 567 | AVPacket *ret = av_packet_alloc(); | ||
| 568 | |||
| 569 | if (!ret) | ||
| 570 | return ret; | ||
| 571 | |||
| 572 | if (av_packet_ref(ret, src)) | ||
| 573 | av_packet_free(&ret); | ||
| 574 | |||
| 575 | return ret; | ||
| 576 | } | ||
| 577 | |||
| 545 | void av_packet_move_ref(AVPacket *dst, AVPacket *src) | 578 | void av_packet_move_ref(AVPacket *dst, AVPacket *src) |
| 546 | { | 579 | { |
| 547 | *dst = *src; | 580 | *dst = *src; |