LCOV - code coverage report
Current view: top level - libavdevice - oss_dec.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 41 0.0 %
Date: 2018-04-19 23:07:36 Functions: 0 3 0.0 %

          Line data    Source code
       1             : /*
       2             :  * Linux audio play 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 <stdint.h>
      25             : 
      26             : #if HAVE_UNISTD_H
      27             : #include <unistd.h>
      28             : #endif
      29             : #include <fcntl.h>
      30             : #include <sys/ioctl.h>
      31             : #include <sys/soundcard.h>
      32             : 
      33             : #include "libavutil/internal.h"
      34             : #include "libavutil/opt.h"
      35             : #include "libavutil/time.h"
      36             : 
      37             : #include "libavcodec/avcodec.h"
      38             : 
      39             : #include "avdevice.h"
      40             : #include "libavformat/internal.h"
      41             : 
      42             : #include "oss.h"
      43             : 
      44           0 : static int audio_read_header(AVFormatContext *s1)
      45             : {
      46           0 :     OSSAudioData *s = s1->priv_data;
      47             :     AVStream *st;
      48             :     int ret;
      49             : 
      50           0 :     st = avformat_new_stream(s1, NULL);
      51           0 :     if (!st) {
      52           0 :         return AVERROR(ENOMEM);
      53             :     }
      54             : 
      55           0 :     ret = ff_oss_audio_open(s1, 0, s1->url);
      56           0 :     if (ret < 0) {
      57           0 :         return AVERROR(EIO);
      58             :     }
      59             : 
      60             :     /* take real parameters */
      61           0 :     st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
      62           0 :     st->codecpar->codec_id = s->codec_id;
      63           0 :     st->codecpar->sample_rate = s->sample_rate;
      64           0 :     st->codecpar->channels = s->channels;
      65             : 
      66           0 :     avpriv_set_pts_info(st, 64, 1, 1000000);  /* 64 bits pts in us */
      67           0 :     return 0;
      68             : }
      69             : 
      70           0 : static int audio_read_packet(AVFormatContext *s1, AVPacket *pkt)
      71             : {
      72           0 :     OSSAudioData *s = s1->priv_data;
      73             :     int ret, bdelay;
      74             :     int64_t cur_time;
      75             :     struct audio_buf_info abufi;
      76             : 
      77           0 :     if ((ret=av_new_packet(pkt, s->frame_size)) < 0)
      78           0 :         return ret;
      79             : 
      80           0 :     ret = read(s->fd, pkt->data, pkt->size);
      81           0 :     if (ret <= 0){
      82           0 :         av_packet_unref(pkt);
      83           0 :         pkt->size = 0;
      84           0 :         if (ret<0)  return AVERROR(errno);
      85           0 :         else        return AVERROR_EOF;
      86             :     }
      87           0 :     pkt->size = ret;
      88             : 
      89             :     /* compute pts of the start of the packet */
      90           0 :     cur_time = av_gettime();
      91           0 :     bdelay = ret;
      92           0 :     if (ioctl(s->fd, SNDCTL_DSP_GETISPACE, &abufi) == 0) {
      93           0 :         bdelay += abufi.bytes;
      94             :     }
      95             :     /* subtract time represented by the number of bytes in the audio fifo */
      96           0 :     cur_time -= (bdelay * 1000000LL) / (s->sample_rate * s->channels);
      97             : 
      98             :     /* convert to wanted units */
      99           0 :     pkt->pts = cur_time;
     100             : 
     101           0 :     if (s->flip_left && s->channels == 2) {
     102             :         int i;
     103           0 :         short *p = (short *) pkt->data;
     104             : 
     105           0 :         for (i = 0; i < ret; i += 4) {
     106           0 :             *p = ~*p;
     107           0 :             p += 2;
     108             :         }
     109             :     }
     110           0 :     return 0;
     111             : }
     112             : 
     113           0 : static int audio_read_close(AVFormatContext *s1)
     114             : {
     115           0 :     OSSAudioData *s = s1->priv_data;
     116             : 
     117           0 :     ff_oss_audio_close(s);
     118           0 :     return 0;
     119             : }
     120             : 
     121             : static const AVOption options[] = {
     122             :     { "sample_rate", "", offsetof(OSSAudioData, sample_rate), AV_OPT_TYPE_INT, {.i64 = 48000}, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
     123             :     { "channels",    "", offsetof(OSSAudioData, channels),    AV_OPT_TYPE_INT, {.i64 = 2},     1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
     124             :     { NULL },
     125             : };
     126             : 
     127             : static const AVClass oss_demuxer_class = {
     128             :     .class_name     = "OSS demuxer",
     129             :     .item_name      = av_default_item_name,
     130             :     .option         = options,
     131             :     .version        = LIBAVUTIL_VERSION_INT,
     132             :     .category       = AV_CLASS_CATEGORY_DEVICE_AUDIO_INPUT,
     133             : };
     134             : 
     135             : AVInputFormat ff_oss_demuxer = {
     136             :     .name           = "oss",
     137             :     .long_name      = NULL_IF_CONFIG_SMALL("OSS (Open Sound System) capture"),
     138             :     .priv_data_size = sizeof(OSSAudioData),
     139             :     .read_header    = audio_read_header,
     140             :     .read_packet    = audio_read_packet,
     141             :     .read_close     = audio_read_close,
     142             :     .flags          = AVFMT_NOFILE,
     143             :     .priv_class     = &oss_demuxer_class,
     144             : };

Generated by: LCOV version 1.13