From 0c383d73060635f3191808c5b4927b55f2ad63c4 Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Tue, 12 Jun 2001 10:11:26 +0000 Subject: [PATCH] added some function to support framestamps & timestamps Original commit message from CVS: added some function to support framestamps & timestamps --- libs/audio/gstaudio.c | 84 +++++++++++++++++++++++++++++++++++++++++++ libs/audio/gstaudio.h | 12 +++++-- 2 files changed, 94 insertions(+), 2 deletions(-) diff --git a/libs/audio/gstaudio.c b/libs/audio/gstaudio.c index 0faca0172d..0b71609482 100644 --- a/libs/audio/gstaudio.c +++ b/libs/audio/gstaudio.c @@ -1,5 +1,89 @@ +/* Gnome-Streamer + * Copyright (C) <1999> Erik Walthinsen + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + #include "gstaudio.h" +int +gst_audio_frame_byte_size (GstPad* pad) +{ +/* calculate byte size of an audio frame + * this should be moved closer to the gstreamer core + * and be implemented for every mime type IMO + * returns 0 if there's an error, or the byte size if everything's ok + */ + + int width = 0; + int channels = 0; + + GstCaps *caps = NULL; + + /* get caps of pad */ + caps = GST_PAD_CAPS (pad); + + if (caps == NULL) + /* ERROR: could not get caps of pad */ + return 0; + + width = gst_caps_get_int (caps, "width"); + channels = gst_caps_get_int (caps, "channels"); + return (width / 8) * channels; +} + +long +gst_audio_frame_length (GstPad* pad, GstBuffer* buf) +/* calculate length of buffer in frames + * this should be moved closer to the gstreamer core + * and be implemented for every mime type IMO + * returns 0 if there's an error, or the number of frames if everything's ok + */ +{ + int frame_byte_size = 0; + + frame_byte_size = gst_audio_frame_byte_size (pad); + if (frame_byte_size == 0) + /* error */ + return 0; + /* FIXME: this function assumes the buffer size to be a whole multiple + * of the frame byte size + */ + return GST_BUFFER_SIZE (buf) / frame_byte_size; +} + +long +gst_audio_frame_rate (GstPad *pad) +/* + * calculate frame rate (based on caps of pad) + * returns 0 if failed, rate if success + */ +{ + GstCaps *caps = NULL; + + /* get caps of pad */ + caps = GST_PAD_CAPS (pad); + + if (caps == NULL) + /* ERROR: could not get caps of pad */ + return 0; + else + return gst_caps_get_int (caps, "rate"); +} + double gst_audio_length (GstPad* pad, GstBuffer* buf) { diff --git a/libs/audio/gstaudio.h b/libs/audio/gstaudio.h index ce35115116..4b0e081cec 100644 --- a/libs/audio/gstaudio.h +++ b/libs/audio/gstaudio.h @@ -25,7 +25,15 @@ #include +/* get byte size of audio frame (based on caps of pad */ +int gst_audio_frame_byte_size (GstPad* pad); + +/* get length in frames of buffer */ +long gst_audio_frame_length (GstPad* pad, GstBuffer* buf); + +/* get frame rate based on caps */ +long gst_audio_frame_rate (GstPad *pad); + /* calculate length in seconds of audio buffer buf based on caps of pad */ - -double gst_audio_length (GstPad* pad, GstBuffer* buf); +double gst_audio_length (GstPad* pad, GstBuffer* buf);