LCOV - code coverage report
Current view: top level - src/libavdevice - oss.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 47 0.0 %
Date: 2017-01-19 23:52:33 Functions: 0 2 0.0 %

          Line data    Source code
       1             : /*
       2             :  * Linux audio play and grab interface
       3             :  * Copyright (c) 2000, 2001 Fabrice Bellard
       4             :  *
       5             :  * This file is part of FFmpeg.
       6             :  *
       7             :  * FFmpeg is free software; you can redistribute it and/or
       8             :  * modify it under the terms of the GNU Lesser General Public
       9             :  * License as published by the Free Software Foundation; either
      10             :  * version 2.1 of the License, or (at your option) any later version.
      11             :  *
      12             :  * FFmpeg is distributed in the hope that it will be useful,
      13             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      15             :  * Lesser General Public License for more details.
      16             :  *
      17             :  * You should have received a copy of the GNU Lesser General Public
      18             :  * License along with FFmpeg; if not, write to the Free Software
      19             :  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
      20             :  */
      21             : 
      22             : #include "config.h"
      23             : 
      24             : #include <string.h>
      25             : 
      26             : #if HAVE_SOUNDCARD_H
      27             : #include <soundcard.h>
      28             : #else
      29             : #include <sys/soundcard.h>
      30             : #endif
      31             : 
      32             : #if HAVE_UNISTD_H
      33             : #include <unistd.h>
      34             : #endif
      35             : #include <fcntl.h>
      36             : #include <sys/ioctl.h>
      37             : 
      38             : #include "libavutil/log.h"
      39             : 
      40             : #include "libavcodec/avcodec.h"
      41             : #include "avdevice.h"
      42             : 
      43             : #include "oss.h"
      44             : 
      45           0 : int ff_oss_audio_open(AVFormatContext *s1, int is_output,
      46             :                       const char *audio_device)
      47             : {
      48           0 :     OSSAudioData *s = s1->priv_data;
      49             :     int audio_fd;
      50             :     int tmp, err;
      51           0 :     char *flip = getenv("AUDIO_FLIP_LEFT");
      52             : 
      53           0 :     if (is_output)
      54           0 :         audio_fd = avpriv_open(audio_device, O_WRONLY);
      55             :     else
      56           0 :         audio_fd = avpriv_open(audio_device, O_RDONLY);
      57           0 :     if (audio_fd < 0) {
      58           0 :         av_log(s1, AV_LOG_ERROR, "%s: %s\n", audio_device, av_err2str(AVERROR(errno)));
      59           0 :         return AVERROR(EIO);
      60             :     }
      61             : 
      62           0 :     if (flip && *flip == '1') {
      63           0 :         s->flip_left = 1;
      64             :     }
      65             : 
      66             :     /* non blocking mode */
      67           0 :     if (!is_output) {
      68           0 :         if (fcntl(audio_fd, F_SETFL, O_NONBLOCK) < 0) {
      69           0 :             av_log(s1, AV_LOG_WARNING, "%s: Could not enable non block mode (%s)\n", audio_device, av_err2str(AVERROR(errno)));
      70             :         }
      71             :     }
      72             : 
      73           0 :     s->frame_size = OSS_AUDIO_BLOCK_SIZE;
      74             : 
      75             : #define CHECK_IOCTL_ERROR(event)                                              \
      76             :     if (err < 0) {                                                            \
      77             :         av_log(s1, AV_LOG_ERROR, #event ": %s\n", av_err2str(AVERROR(errno)));\
      78             :         goto fail;                                                            \
      79             :     }
      80             : 
      81             :     /* select format : favour native format
      82             :      * We don't CHECK_IOCTL_ERROR here because even if failed OSS still may be
      83             :      * usable. If OSS is not usable the SNDCTL_DSP_SETFMTS later is going to
      84             :      * fail anyway. */
      85           0 :     err = ioctl(audio_fd, SNDCTL_DSP_GETFMTS, &tmp);
      86           0 :     if (err < 0) {
      87           0 :         av_log(s1, AV_LOG_WARNING, "SNDCTL_DSP_GETFMTS: %s\n", av_err2str(AVERROR(errno)));
      88             :     }
      89             : 
      90             : #if HAVE_BIGENDIAN
      91             :     if (tmp & AFMT_S16_BE) {
      92             :         tmp = AFMT_S16_BE;
      93             :     } else if (tmp & AFMT_S16_LE) {
      94             :         tmp = AFMT_S16_LE;
      95             :     } else {
      96             :         tmp = 0;
      97             :     }
      98             : #else
      99           0 :     if (tmp & AFMT_S16_LE) {
     100           0 :         tmp = AFMT_S16_LE;
     101           0 :     } else if (tmp & AFMT_S16_BE) {
     102           0 :         tmp = AFMT_S16_BE;
     103             :     } else {
     104           0 :         tmp = 0;
     105             :     }
     106             : #endif
     107             : 
     108           0 :     switch(tmp) {
     109             :     case AFMT_S16_LE:
     110           0 :         s->codec_id = AV_CODEC_ID_PCM_S16LE;
     111           0 :         break;
     112             :     case AFMT_S16_BE:
     113           0 :         s->codec_id = AV_CODEC_ID_PCM_S16BE;
     114           0 :         break;
     115             :     default:
     116           0 :         av_log(s1, AV_LOG_ERROR, "Soundcard does not support 16 bit sample format\n");
     117           0 :         close(audio_fd);
     118           0 :         return AVERROR(EIO);
     119             :     }
     120           0 :     err=ioctl(audio_fd, SNDCTL_DSP_SETFMT, &tmp);
     121           0 :     CHECK_IOCTL_ERROR(SNDCTL_DSP_SETFMTS)
     122             : 
     123           0 :     tmp = (s->channels == 2);
     124           0 :     err = ioctl(audio_fd, SNDCTL_DSP_STEREO, &tmp);
     125           0 :     CHECK_IOCTL_ERROR(SNDCTL_DSP_STEREO)
     126             : 
     127           0 :     tmp = s->sample_rate;
     128           0 :     err = ioctl(audio_fd, SNDCTL_DSP_SPEED, &tmp);
     129           0 :     CHECK_IOCTL_ERROR(SNDCTL_DSP_SPEED)
     130           0 :     s->sample_rate = tmp; /* store real sample rate */
     131           0 :     s->fd = audio_fd;
     132             : 
     133           0 :     return 0;
     134             :  fail:
     135           0 :     close(audio_fd);
     136           0 :     return AVERROR(EIO);
     137             : #undef CHECK_IOCTL_ERROR
     138             : }
     139             : 
     140           0 : int ff_oss_audio_close(OSSAudioData *s)
     141             : {
     142           0 :     close(s->fd);
     143           0 :     return 0;
     144             : }

Generated by: LCOV version 1.12