gstrtppcmupay.c 3.8 KB
Newer Older
1
/* GStreamer
2
 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
Edgard Lima's avatar
Edgard Lima committed
3
 * Copyright (C) <2005> Edgard Lima <edgard.lima@gmail.com>
4
 * Copyright (C) <2005> Nokia Corporation <kai.vehmanen@nokia.com>
5 6 7 8 9 10 11 12 13
 *
 * 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
14 15 16 17
 * 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
Tim-Philipp Müller's avatar
Tim-Philipp Müller committed
18 19
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 * Boston, MA 02110-1301, USA.
20 21 22 23 24 25 26 27 28 29
 */

#ifdef HAVE_CONFIG_H
#  include "config.h"
#endif

#include <stdlib.h>
#include <string.h>
#include <gst/rtp/gstrtpbuffer.h>

30
#include "gstrtppcmupay.h"
31

32 33
static GstStaticPadTemplate gst_rtp_pcmu_pay_sink_template =
GST_STATIC_PAD_TEMPLATE ("sink",
34 35
    GST_PAD_SINK,
    GST_PAD_ALWAYS,
36
    GST_STATIC_CAPS ("audio/x-mulaw, channels=(int)1, rate=(int)8000")
37 38
    );

39
static GstStaticPadTemplate gst_rtp_pcmu_pay_src_template =
40
    GST_STATIC_PAD_TEMPLATE ("src",
41 42 43 44
    GST_PAD_SRC,
    GST_PAD_ALWAYS,
    GST_STATIC_CAPS ("application/x-rtp, "
        "media = (string) \"audio\", "
45
        "payload = (int) " GST_RTP_PAYLOAD_PCMU_STRING ", "
46 47 48 49
        "clock-rate = (int) 8000, " "encoding-name = (string) \"PCMU\"; "
        "application/x-rtp, "
        "media = (string) \"audio\", "
        "payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
50
        "clock-rate = (int) [1, MAX ], " "encoding-name = (string) \"PCMU\"")
51 52
    );

53
static gboolean gst_rtp_pcmu_pay_setcaps (GstRTPBasePayload * payload,
54 55
    GstCaps * caps);

Wim Taymans's avatar
Wim Taymans committed
56 57
#define gst_rtp_pcmu_pay_parent_class parent_class
G_DEFINE_TYPE (GstRtpPcmuPay, gst_rtp_pcmu_pay,
58
    GST_TYPE_RTP_BASE_AUDIO_PAYLOAD);
59

60
static void
Wim Taymans's avatar
Wim Taymans committed
61
gst_rtp_pcmu_pay_class_init (GstRtpPcmuPayClass * klass)
62
{
Wim Taymans's avatar
Wim Taymans committed
63
  GstElementClass *gstelement_class;
64
  GstRTPBasePayloadClass *gstrtpbasepayload_class;
Wim Taymans's avatar
Wim Taymans committed
65 66

  gstelement_class = (GstElementClass *) klass;
67
  gstrtpbasepayload_class = (GstRTPBasePayloadClass *) klass;
68

69 70 71 72
  gst_element_class_add_static_pad_template (gstelement_class,
      &gst_rtp_pcmu_pay_sink_template);
  gst_element_class_add_static_pad_template (gstelement_class,
      &gst_rtp_pcmu_pay_src_template);
Wim Taymans's avatar
Wim Taymans committed
73

74
  gst_element_class_set_static_metadata (gstelement_class, "RTP PCMU payloader",
75
      "Codec/Payloader/Network/RTP",
76
      "Payload-encodes PCMU audio into a RTP packet",
Edgard Lima's avatar
Edgard Lima committed
77
      "Edgard Lima <edgard.lima@gmail.com>");
78

79
  gstrtpbasepayload_class->set_caps = gst_rtp_pcmu_pay_setcaps;
80 81 82
}

static void
Wim Taymans's avatar
Wim Taymans committed
83
gst_rtp_pcmu_pay_init (GstRtpPcmuPay * rtppcmupay)
84
{
85
  GstRTPBaseAudioPayload *rtpbaseaudiopayload;
86

87
  rtpbaseaudiopayload = GST_RTP_BASE_AUDIO_PAYLOAD (rtppcmupay);
88

89
  GST_RTP_BASE_PAYLOAD (rtppcmupay)->pt = GST_RTP_PAYLOAD_PCMU;
90
  GST_RTP_BASE_PAYLOAD (rtppcmupay)->clock_rate = 8000;
91

92 93
  /* tell rtpbaseaudiopayload that this is a sample based codec */
  gst_rtp_base_audio_payload_set_sample_based (rtpbaseaudiopayload);
94

95
  /* octet-per-sample is 1 for PCM */
96
  gst_rtp_base_audio_payload_set_sample_options (rtpbaseaudiopayload, 1);
97 98
}

99
static gboolean
100
gst_rtp_pcmu_pay_setcaps (GstRTPBasePayload * payload, GstCaps * caps)
101
{
102 103
  gboolean res;

104 105
  gst_rtp_base_payload_set_options (payload, "audio",
      payload->pt != GST_RTP_PAYLOAD_PCMU, "PCMU", 8000);
106
  res = gst_rtp_base_payload_set_outcaps (payload, NULL);
107

108
  return res;
109 110 111
}

gboolean
112
gst_rtp_pcmu_pay_plugin_init (GstPlugin * plugin)
113
{
114
  return gst_element_register (plugin, "rtppcmupay",
115
      GST_RANK_SECONDARY, GST_TYPE_RTP_PCMU_PAY);
116
}