mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-11-01 12:07:31 +01:00
The ffmpeg submodule held prebuilt libraries for every platform next to the sources (about 1.5 GB checked out), and nothing uses those any more. Only the needed sources are copied in, from the submodule's commit, along with every header and template they include. The path is new, so checking out commits on either side of this works. It's also cut down to what PPSSPP uses: the H.264, AAC, MP3, ATRAC3 and ATRAC3+ decoders, the H.264 parser, the demuxers as before, and the FFV1 encoder, AVI muxer and file protocol for AVI dumping. config.h takes its CONFIG_ values from FFmpeg 3.0.2's own configure run with just those enabled. The raw H.264 demuxer stays even though nothing opens raw H.264: probing PSMF data uses it to identify the video stream's codec, which otherwise comes out as none. On top of that: - The files nothing links (configure would build them, but they're never pulled out of the static library, going by the GCC link map) are left out: mostly libavutil's crypto and hashing and the alternative DCT/IDCT/FFT versions. - libswresample isn't built, now that nothing uses it. - The H.264 decoder only does 8-bit video, which is all the PSP has. The SPS parser rejects any other bit depth, and the DSP files no longer build their 9- to 16-bit variants, which the linker kept because the init functions pick one by bit depth at run time. That's 160 files to compile instead of 277, and 391 of FFmpeg's vendored, about 5.8 MB. The README in ext/ffmpeg has what was done, the PPSSPP patches in the copy, how to add a component, and the tradeoffs. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
165 lines
3.7 KiB
C
165 lines
3.7 KiB
C
/*
|
|
* Copyright (c) 2009 Baptiste Coudurier <baptiste.coudurier@gmail.com>
|
|
*
|
|
* This file is part of FFmpeg.
|
|
*
|
|
* FFmpeg is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
* License as published by the Free Software Foundation; either
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
*
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
* License along with FFmpeg; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
*/
|
|
|
|
#include "config.h"
|
|
|
|
#if HAVE_UNISTD_H
|
|
#include <unistd.h>
|
|
#endif
|
|
#if HAVE_IO_H
|
|
#include <io.h>
|
|
#endif
|
|
#if HAVE_CRYPTGENRANDOM
|
|
#include <windows.h>
|
|
#include <wincrypt.h>
|
|
#endif
|
|
#include <fcntl.h>
|
|
#include <math.h>
|
|
#include <time.h>
|
|
#include <string.h>
|
|
#include "avassert.h"
|
|
#include "internal.h"
|
|
#include "intreadwrite.h"
|
|
#include "timer.h"
|
|
#include "random_seed.h"
|
|
#include "sha.h"
|
|
|
|
#ifndef TEST
|
|
#define TEST 0
|
|
#endif
|
|
|
|
static int read_random(uint32_t *dst, const char *file)
|
|
{
|
|
#if HAVE_UNISTD_H
|
|
int fd = avpriv_open(file, O_RDONLY);
|
|
int err = -1;
|
|
|
|
if (fd == -1)
|
|
return -1;
|
|
err = read(fd, dst, sizeof(*dst));
|
|
close(fd);
|
|
|
|
return err;
|
|
#else
|
|
return -1;
|
|
#endif
|
|
}
|
|
|
|
static uint32_t get_generic_seed(void)
|
|
{
|
|
uint8_t tmp[120];
|
|
struct AVSHA *sha = (void*)tmp;
|
|
clock_t last_t = 0;
|
|
static uint64_t i = 0;
|
|
static uint32_t buffer[512] = { 0 };
|
|
unsigned char digest[20];
|
|
uint64_t last_i = i;
|
|
|
|
av_assert0(sizeof(tmp) >= av_sha_size);
|
|
|
|
if(TEST){
|
|
memset(buffer, 0, sizeof(buffer));
|
|
last_i = i = 0;
|
|
}else{
|
|
#ifdef AV_READ_TIME
|
|
buffer[13] ^= AV_READ_TIME();
|
|
buffer[41] ^= AV_READ_TIME()>>32;
|
|
#endif
|
|
}
|
|
|
|
for (;;) {
|
|
clock_t t = clock();
|
|
|
|
if (last_t == t) {
|
|
buffer[i & 511]++;
|
|
} else {
|
|
buffer[++i & 511] += (t - last_t) % 3294638521U;
|
|
if (last_i && i - last_i > 4 || i - last_i > 64 || TEST && i - last_i > 8)
|
|
break;
|
|
}
|
|
last_t = t;
|
|
}
|
|
|
|
if(TEST) {
|
|
buffer[0] = buffer[1] = 0;
|
|
} else {
|
|
#ifdef AV_READ_TIME
|
|
buffer[111] += AV_READ_TIME();
|
|
#endif
|
|
}
|
|
|
|
av_sha_init(sha, 160);
|
|
av_sha_update(sha, (const uint8_t *)buffer, sizeof(buffer));
|
|
av_sha_final(sha, digest);
|
|
return AV_RB32(digest) + AV_RB32(digest + 16);
|
|
}
|
|
|
|
uint32_t av_get_random_seed(void)
|
|
{
|
|
uint32_t seed;
|
|
|
|
#if HAVE_CRYPTGENRANDOM
|
|
HCRYPTPROV provider;
|
|
if (CryptAcquireContext(&provider, NULL, NULL, PROV_RSA_FULL,
|
|
CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) {
|
|
BOOL ret = CryptGenRandom(provider, sizeof(seed), (PBYTE) &seed);
|
|
CryptReleaseContext(provider, 0);
|
|
if (ret)
|
|
return seed;
|
|
}
|
|
#endif
|
|
|
|
#if HAVE_ARC4RANDOM
|
|
return arc4random();
|
|
#endif
|
|
|
|
if (read_random(&seed, "/dev/urandom") == sizeof(seed))
|
|
return seed;
|
|
if (read_random(&seed, "/dev/random") == sizeof(seed))
|
|
return seed;
|
|
return get_generic_seed();
|
|
}
|
|
|
|
#if TEST
|
|
#undef printf
|
|
#define N 256
|
|
#include <stdio.h>
|
|
|
|
int main(void)
|
|
{
|
|
int i, j, retry;
|
|
uint32_t seeds[N];
|
|
|
|
for (retry=0; retry<3; retry++){
|
|
for (i=0; i<N; i++){
|
|
seeds[i] = av_get_random_seed();
|
|
for (j=0; j<i; j++)
|
|
if (seeds[j] == seeds[i])
|
|
goto retry;
|
|
}
|
|
printf("seeds OK\n");
|
|
return 0;
|
|
retry:;
|
|
}
|
|
printf("FAIL at %d with %X\n", j, seeds[j]);
|
|
return 1;
|
|
}
|
|
#endif
|