seeds an AVLFG from binary data.
Unified · Split
| @@ -15,6 +15,9 @@ libavutil: 2015-08-28 · 14 unmodified lines | ||
| 15 | 15 | |
| 16 | 16 | API changes, most recent first: |
| 17 | 17 | |
| 18 | +2017-01-22 - xxxxxxx - lavu 55.44.100 - lfg.h | |
| 19 | + Add av_lfg_init_from_data(). | |
| 20 | + | |
| 18 | 21 | 2017-01-xx - xxxxxxx - lavc 57.74.100 - vaapi.h |
| 19 | 22 | Deprecate struct vaapi_context and the vaapi.h installed header. |
| 20 | 23 | Callers should set AVCodecContext.hw_frames_ctx instead. |
| @@ -23,7 +23,9 @@ · 22 unmodified lines | ||
| 23 | 23 | #include <limits.h> |
| 24 | 24 | #include <math.h> |
| 25 | 25 | #include "lfg.h" |
| 26 | +#include "crc.h" | |
| 26 | 27 | #include "md5.h" |
| 28 | +#include "error.h" | |
| 27 | 29 | #include "intreadwrite.h" |
| 28 | 30 | #include "attributes.h" |
| 29 | 31 | |
| @@ -58,3 +60,28 @@ void av_bmg_get(AVLFG *lfg, double out[2]) · 28 unmodified lines | ||
| 58 | 60 | out[0] = x1 * w; |
| 59 | 61 | out[1] = x2 * w; |
| 60 | 62 | } |
| 63 | + | |
| 64 | +int av_lfg_init_from_data(AVLFG *c, const uint8_t *data, unsigned int length) { | |
| 65 | + unsigned int beg, end, segm; | |
| 66 | + const AVCRC *avcrc; | |
| 67 | + uint32_t crc = 1; | |
| 68 | + | |
| 69 | + /* avoid integer overflow in the loop below. */ | |
| 70 | + if (length > (UINT_MAX / 128U)) return AVERROR(EINVAL); | |
| 71 | + | |
| 72 | + c->index = 0; | |
| 73 | + avcrc = av_crc_get_table(AV_CRC_32_IEEE); /* This can't fail. It's a well-defined table in crc.c */ | |
| 74 | + | |
| 75 | + /* across 64 segments of the incoming data, | |
| 76 | + * do a running crc of each segment and store the crc as the state for that slot. | |
| 77 | + * this works even if the length of the segment is 0 bytes. */ | |
| 78 | + beg = 0; | |
| 79 | + for (segm = 0;segm < 64;segm++) { | |
| 80 | + end = (((segm + 1) * length) / 64); | |
| 81 | + crc = av_crc(avcrc, crc, data + beg, end - beg); | |
| 82 | + c->state[segm] = (unsigned int)crc; | |
| 83 | + beg = end; | |
| 84 | + } | |
| 85 | + | |
| 86 | + return 0; | |
| 87 | +} | |
| @@ -22,6 +22,8 @@ · 21 unmodified lines | ||
| 22 | 22 | #ifndef AVUTIL_LFG_H |
| 23 | 23 | #define AVUTIL_LFG_H |
| 24 | 24 | |
| 25 | +#include <stdint.h> | |
| 26 | + | |
| 25 | 27 | typedef struct AVLFG { |
| 26 | 28 | unsigned int state[64]; |
| 27 | 29 | int index; |
| @@ -29,6 +31,13 @@ typedef struct AVLFG { · 1 unmodified line | ||
| 29 | 31 | |
| 30 | 32 | void av_lfg_init(AVLFG *c, unsigned int seed); |
| 31 | 33 | |
| 34 | +/** | |
| 35 | + * Seed the state of the ALFG using binary data. | |
| 36 | + * | |
| 37 | + * Return value: 0 on success, negative value (AVERROR) on failure. | |
| 38 | + */ | |
| 39 | +int av_lfg_init_from_data(AVLFG *c, const uint8_t *data, unsigned int length); | |
| 40 | + | |
| 32 | 41 | /** |
| 33 | 42 | * Get the next random unsigned 32-bit number using an ALFG. |
| 34 | 43 | * |
| @@ -79,7 +79,7 @@ · 78 unmodified lines | ||
| 79 | 79 | */ |
| 80 | 80 | |
| 81 | 81 | #define LIBAVUTIL_VERSION_MAJOR 55 |
| 82 | −#define LIBAVUTIL_VERSION_MINOR 43 | |
| 82 | +#define LIBAVUTIL_VERSION_MINOR 44 | |
| 83 | 83 | #define LIBAVUTIL_VERSION_MICRO 100 |
| 84 | 84 | |
| 85 | 85 | #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ |