History

libavutil: add av_lfg_init_from_data() function

seeds an AVLFG from binary data.

Jonathan Campbell committed 10 years ago

Commit 76c5a691 parent 0a5add44 files · +40 −1Browse files

Unified · Split

4 files
  1. doc/APIchanges +3 −0
  2. libavutil/lfg.c +27 −0
  3. libavutil/lfg.h +9 −0
  4. libavutil/version.h +1 −1
doc/APIchanges+3−0
@@ -15,6 +15,9 @@ libavutil: 2015-08-28 · 14 unmodified lines
15 15
16API changes, most recent first:16API changes, most recent first:
17 17
182017-01-22 - xxxxxxx - lavu 55.44.100 - lfg.h
19 Add av_lfg_init_from_data().
20
182017-01-xx - xxxxxxx - lavc 57.74.100 - vaapi.h212017-01-xx - xxxxxxx - lavc 57.74.100 - vaapi.h
19 Deprecate struct vaapi_context and the vaapi.h installed header.22 Deprecate struct vaapi_context and the vaapi.h installed header.
20 Callers should set AVCodecContext.hw_frames_ctx instead.23 Callers should set AVCodecContext.hw_frames_ctx instead.
libavutil/lfg.c+27−0
@@ -23,7 +23,9 @@ · 22 unmodified lines
23#include <limits.h>23#include <limits.h>
24#include <math.h>24#include <math.h>
25#include "lfg.h"25#include "lfg.h"
26#include "crc.h"
26#include "md5.h"27#include "md5.h"
28#include "error.h"
27#include "intreadwrite.h"29#include "intreadwrite.h"
28#include "attributes.h"30#include "attributes.h"
29 31
@@ -58,3 +60,28 @@ void av_bmg_get(AVLFG *lfg, double out[2]) · 28 unmodified lines
58 out[0] = x1 * w;60 out[0] = x1 * w;
59 out[1] = x2 * w;61 out[1] = x2 * w;
60}62}
63
64int 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}
libavutil/lfg.h+9−0
@@ -22,6 +22,8 @@ · 21 unmodified lines
22#ifndef AVUTIL_LFG_H22#ifndef AVUTIL_LFG_H
23#define AVUTIL_LFG_H23#define AVUTIL_LFG_H
24 24
25#include <stdint.h>
26
25typedef struct AVLFG {27typedef struct AVLFG {
26 unsigned int state[64];28 unsigned int state[64];
27 int index;29 int index;
@@ -29,6 +31,13 @@ typedef struct AVLFG { · 1 unmodified line
29 31
30void av_lfg_init(AVLFG *c, unsigned int seed);32void 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 */
39int av_lfg_init_from_data(AVLFG *c, const uint8_t *data, unsigned int length);
40
32/**41/**
33 * Get the next random unsigned 32-bit number using an ALFG.42 * Get the next random unsigned 32-bit number using an ALFG.
34 *43 *
libavutil/version.h+1−1
@@ -79,7 +79,7 @@ · 78 unmodified lines
79 */79 */
80 80
81#define LIBAVUTIL_VERSION_MAJOR 5581#define LIBAVUTIL_VERSION_MAJOR 55
82#define LIBAVUTIL_VERSION_MINOR 4382#define LIBAVUTIL_VERSION_MINOR 44
83#define LIBAVUTIL_VERSION_MICRO 10083#define LIBAVUTIL_VERSION_MICRO 100
84 84
85#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \85#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t