| Line | Branch | Exec | Source |
|---|---|---|---|
| 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 | |||
| 19 | #include <string.h> | ||
| 20 | |||
| 21 | #include "libavutil/avutil.h" | ||
| 22 | #include "libavutil/error.h" | ||
| 23 | #include "libavutil/mem.h" | ||
| 24 | #include "libavutil/rational.h" | ||
| 25 | |||
| 26 | #include "libavcodec/packet.h" | ||
| 27 | |||
| 28 | #include "packet_internal.h" | ||
| 29 | |||
| 30 | 133 | static void get_packet_defaults(AVPacket *pkt) | |
| 31 | { | ||
| 32 | 133 | memset(pkt, 0, sizeof(*pkt)); | |
| 33 | |||
| 34 | 133 | pkt->pts = AV_NOPTS_VALUE; | |
| 35 | 133 | pkt->dts = AV_NOPTS_VALUE; | |
| 36 | 133 | pkt->pos = -1; | |
| 37 | 133 | pkt->time_base = av_make_q(0, 1); | |
| 38 | 133 | } | |
| 39 | |||
| 40 | 493950 | int ff_packet_list_put(PacketList *packet_buffer, | |
| 41 | AVPacket *pkt, | ||
| 42 | int (*copy)(AVPacket *dst, const AVPacket *src), | ||
| 43 | int flags) | ||
| 44 | { | ||
| 45 | 493950 | PacketListEntry *pktl = av_malloc(sizeof(*pktl)); | |
| 46 | 493950 | unsigned int update_end_point = 1; | |
| 47 | int ret; | ||
| 48 | |||
| 49 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 493950 times.
|
493950 | if (!pktl) |
| 50 | ✗ | return AVERROR(ENOMEM); | |
| 51 | |||
| 52 |
2/2✓ Branch 0 taken 133 times.
✓ Branch 1 taken 493817 times.
|
493950 | if (copy) { |
| 53 | 133 | get_packet_defaults(&pktl->pkt); | |
| 54 | 133 | ret = copy(&pktl->pkt, pkt); | |
| 55 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 133 times.
|
133 | if (ret < 0) { |
| 56 | ✗ | av_free(pktl); | |
| 57 | ✗ | return ret; | |
| 58 | } | ||
| 59 | } else { | ||
| 60 | 493817 | ret = av_packet_make_refcounted(pkt); | |
| 61 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 493817 times.
|
493817 | if (ret < 0) { |
| 62 | ✗ | av_free(pktl); | |
| 63 | ✗ | return ret; | |
| 64 | } | ||
| 65 | 493817 | av_packet_move_ref(&pktl->pkt, pkt); | |
| 66 | } | ||
| 67 | |||
| 68 | 493950 | pktl->next = NULL; | |
| 69 | |||
| 70 |
2/2✓ Branch 0 taken 309218 times.
✓ Branch 1 taken 184732 times.
|
493950 | if (packet_buffer->head) { |
| 71 |
2/2✓ Branch 0 taken 20 times.
✓ Branch 1 taken 309198 times.
|
309218 | if (flags & FF_PACKETLIST_FLAG_PREPEND) { |
| 72 | 20 | pktl->next = packet_buffer->head; | |
| 73 | 20 | packet_buffer->head = pktl; | |
| 74 | 20 | update_end_point = 0; | |
| 75 | } else { | ||
| 76 | 309198 | packet_buffer->tail->next = pktl; | |
| 77 | } | ||
| 78 | } else | ||
| 79 | 184732 | packet_buffer->head = pktl; | |
| 80 | |||
| 81 |
2/2✓ Branch 0 taken 493930 times.
✓ Branch 1 taken 20 times.
|
493950 | if (update_end_point) { |
| 82 | /* Add the packet in the buffered packet list. */ | ||
| 83 | 493930 | packet_buffer->tail = pktl; | |
| 84 | } | ||
| 85 | |||
| 86 | 493950 | return 0; | |
| 87 | } | ||
| 88 | |||
| 89 | 441509 | int ff_packet_list_get(PacketList *pkt_buffer, | |
| 90 | AVPacket *pkt) | ||
| 91 | { | ||
| 92 | 441509 | PacketListEntry *pktl = pkt_buffer->head; | |
| 93 |
2/2✓ Branch 0 taken 54 times.
✓ Branch 1 taken 441455 times.
|
441509 | if (!pktl) |
| 94 | 54 | return AVERROR(EAGAIN); | |
| 95 | 441455 | *pkt = pktl->pkt; | |
| 96 | 441455 | pkt_buffer->head = pktl->next; | |
| 97 |
2/2✓ Branch 0 taken 180541 times.
✓ Branch 1 taken 260914 times.
|
441455 | if (!pkt_buffer->head) |
| 98 | 180541 | pkt_buffer->tail = NULL; | |
| 99 | 441455 | av_freep(&pktl); | |
| 100 | 441455 | return 0; | |
| 101 | } | ||
| 102 | |||
| 103 | 58243 | void ff_packet_list_free(PacketList *pkt_buf) | |
| 104 | { | ||
| 105 | 58243 | PacketListEntry *tmp = pkt_buf->head; | |
| 106 | |||
| 107 |
2/2✓ Branch 0 taken 82652 times.
✓ Branch 1 taken 58243 times.
|
140895 | while (tmp) { |
| 108 | 82652 | PacketListEntry *pktl = tmp; | |
| 109 | 82652 | tmp = pktl->next; | |
| 110 | 82652 | av_packet_unref(&pktl->pkt); | |
| 111 | 82652 | av_freep(&pktl); | |
| 112 | } | ||
| 113 | 58243 | pkt_buf->head = pkt_buf->tail = NULL; | |
| 114 | 58243 | } | |
| 115 |