Libav
cpu.c
Go to the documentation of this file.
1 /*
2  * This file is part of Libav.
3  *
4  * Libav 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  * Libav 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 Libav; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #ifdef __APPLE__
20 #include <sys/sysctl.h>
21 #elif defined(__linux__)
22 #include <asm/cputable.h>
23 #include <linux/auxvec.h>
24 #include <fcntl.h>
25 #include <unistd.h>
26 #elif defined(__OpenBSD__)
27 #include <sys/param.h>
28 #include <sys/sysctl.h>
29 #include <machine/cpu.h>
30 #elif defined(__AMIGAOS4__)
31 #include <exec/exec.h>
32 #include <interfaces/exec.h>
33 #include <proto/exec.h>
34 #endif /* __APPLE__ */
35 
36 #include "libavutil/cpu.h"
37 #include "libavutil/cpu_internal.h"
38 #include "config.h"
39 
45 {
46 #if HAVE_ALTIVEC
47 #ifdef __AMIGAOS4__
48  ULONG result = 0;
49  extern struct ExecIFace *IExec;
50 
51  IExec->GetCPUInfoTags(GCIT_VectorUnit, &result, TAG_DONE);
52  if (result == VECTORTYPE_ALTIVEC)
53  return AV_CPU_FLAG_ALTIVEC;
54  return 0;
55 #elif defined(__APPLE__) || defined(__OpenBSD__)
56 #ifdef __OpenBSD__
57  int sels[2] = {CTL_MACHDEP, CPU_ALTIVEC};
58 #else
59  int sels[2] = {CTL_HW, HW_VECTORUNIT};
60 #endif
61  int has_vu = 0;
62  size_t len = sizeof(has_vu);
63  int err;
64 
65  err = sysctl(sels, 2, &has_vu, &len, NULL, 0);
66 
67  if (err == 0)
68  return has_vu ? AV_CPU_FLAG_ALTIVEC : 0;
69  return 0;
70 #elif defined(__linux__)
71  // The linux kernel could have the altivec support disabled
72  // even if the cpu has it.
73  int i, ret = 0;
74  int fd = open("/proc/self/auxv", O_RDONLY);
75  unsigned long buf[64] = { 0 };
76  ssize_t count;
77 
78  if (fd < 0)
79  return 0;
80 
81  while ((count = read(fd, buf, sizeof(buf))) > 0) {
82  for (i = 0; i < count / sizeof(*buf); i += 2) {
83  if (buf[i] == AT_NULL)
84  goto out;
85  if (buf[i] == AT_HWCAP) {
86  if (buf[i + 1] & PPC_FEATURE_HAS_ALTIVEC)
87  ret = AV_CPU_FLAG_ALTIVEC;
88  goto out;
89  }
90  }
91  }
92 
93 out:
94  close(fd);
95  return ret;
96 #elif CONFIG_RUNTIME_CPUDETECT
97  int proc_ver;
98  // Support of mfspr PVR emulation added in Linux 2.6.17.
99  __asm__ volatile("mfspr %0, 287" : "=r" (proc_ver));
100  proc_ver >>= 16;
101  if (proc_ver & 0x8000 ||
102  proc_ver == 0x000c ||
103  proc_ver == 0x0039 || proc_ver == 0x003c ||
104  proc_ver == 0x0044 || proc_ver == 0x0045 ||
105  proc_ver == 0x0070)
106  return AV_CPU_FLAG_ALTIVEC;
107  return 0;
108 #else
109  // Since we were compiled for AltiVec, just assume we have it
110  // until someone comes up with a proper way (not involving signal hacks).
111  return AV_CPU_FLAG_ALTIVEC;
112 #endif /* __AMIGAOS4__ */
113 #endif /* HAVE_ALTIVEC */
114  return 0;
115 }
#define AV_CPU_FLAG_ALTIVEC
standard
Definition: cpu.h:56
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_dlog(ac->avr, "%d samples - audio_convert: %s to %s (dithered)\", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> out
int ff_get_cpu_flags_ppc(void)
This function MAY rely on signal() or fork() in order to make sure AltiVec is present.
Definition: cpu.c:44
NULL
Definition: eval.c:55
static void close(AVCodecParserContext *s)
Definition: h264_parser.c:490
int len