RTP_payload_format_for_DRA_audio
基于RTP协议的打包及解包

H.264视频在android手机端的解码与播放文/南京邮电大学张永芹龚建荣摘要:本文实现了手机终端通过移动无线网络与媒体服务器进行通信,并就开发过程中的几个技术难点的解决方法进行了说明。
首先详细分析说明了rtp 打包,解包的流程,这是视频传输的基础;然后在RTP传输过程中,针对发送数据快而处理速度慢的问题,采用多线程并发机制予以解决;面对大量,而且不稳定的数据包,本文针对各个环节自己的特点,设计了多级缓冲处理机制,使得视频播放更加流畅、平稳。
接着,对于分析和解码的先后次序的问题,则采用线程协作的思想,利用消费者,生产者模式,保证了视频数据的时序性。
最后对于视频解码部分,则利用现有解码方法进行平台移植,深度简化代码,合理处理c层和java层的分工。
最后实践证明,采用本文提供的方法,视频传输、播放成功,而且android手机端视频播放延时短,流畅,平稳。
关键词:H.264 RTP 多级缓冲线程协作 android随着无线网络和智能手机的发展,智能手机与人们日常生活联系越来越紧密,娱乐、商务应用、金融应用、交通出行各种功能的软件大批涌现,使得人们的生活丰富多彩、快捷便利,也让它成为人们生活中不可取代的一部分。
其中,多媒体由于其直观性和实时性,应用范围越来越广,视频的解码与播放也就成为研究的热点。
H.264标准技术日渐成熟,采用了统一的VLC符号编码,高精度、多模式的位移估计,基于4×4块的整数变换、分层的编码语法等。
这些措施使得H.264算法具有很高的编码效率,在相同的重建图像质量下,能够比H.263节约50%左右的码率。
而且H.264的码流结构网络适应性强,增加了差错恢复能力。
正好适用于带宽受限,差错率高的无线网络。
本文结合ffmpeg开源代码中的解码方法,采用多线程接收数据包,多级缓冲数据,接收和解码并行双线程操作等方法,缓解了由于传输的数据量大、速度快而导致的数据堵塞、解码出错、视频画面迟钝、延迟等问题。
webrtc 解码 流程

webrtc 解码流程
WebRTC解码流程主要包括以下几个步骤:
1. 解码器初始化:在开始解码之前,需要初始化解码器,包括设置解码器参数、配置解码器等。
2. 获取解码数据:从数据源中获取需要解码的数据,包括视频帧数据和音频帧数据。
3. 提交解码任务:将获取到的数据提交给解码器进行解码,解码器会将数据转换成原始的像素格式或者音频样本格式。
4. 渲染解码结果:将解码器输出的原始像素格式或者音频样本格式的数据进行渲染,转换成用户可以观看的视频或者音频。
5. 释放资源:在解码完成后,需要释放解码器占用的资源,包括内存、文件句柄等。
需要注意的是,具体的WebRTC解码流程可能因为不同的实现方式而有所差异。
在实际应用中,需要根据具体情况进行调整和优化。
在MPEG TS中复用DRA音频流

比特数
8 8 4 6 2 1 1 1 1
8
16
24
8
符号
uimsbf uimsbf uimsbf uimsbf uimsbf bslbf bslbf bslbf ‘0’
uimsbf
bslbf
bslbf
bslbf
descriptor_tag:8 比特字段,对于 DRA 音频流描述符,descriptor_tag 的值为 0xA0。 descriptor_length:8 比特字段,指示 DRA 音频流描述符的长度(descriptor_length 之 后的字节数)。对于 DRA 音频流描述符来说,其最小值是 2,即该字段之后至少要包含 16 比 特的描述符内容。 sample_rate_index:4 比特字段,指示编码音频流的采样率,如表 3 所示。
4. DRA音频流描述符(DRA audio stream descriptor)
DRA_audio_stream_descriptor 的 目 的 是 为 综 合 解 码 接 收 机 ( IRD , Integrated Receiver-Decoder)提供DRA音频解码配置信息。
该描述符位于PSI的PMT中,同MPEG-2描述符的语法一致,以一个8比特的descriptor_tag 和 一 个 8 比 特 的 descriptor_length 开 始 , 然 后 包 含 DRA 音 频 信 息 的 描 述 字 段 如
5. STD 音频缓冲区大小
DRA音频访问单元AU(Access Unit)是一个DRA帧。一个DRA典型帧包含1024个音频采样 数据(见5.3.3),其持续时间可根据采样频率计算得出:
持续时间 = 1024 / 采样率 对于一路MPEG-2传输流,主音频缓冲区大小BSn定义为:
IPS-1000系列VoIP综合接入系统用户手册V1.05

IPS-1000系列VoIP综合接入系统用户手册版本:V1.05目录1.前言 (1)2.概述 (2)3.系统指标 (3)3.1功能、性能 (3)3.2工作条件 (3)3.3配置 (4)4.结构 (5)4.1VIP板面板图 (5)4.2面板 (5)4.3出线 (6)4.4系列结构标准 (6)5.安装和操作 (7)5.1IPS设置简介 (7)5.2产品安装和呼叫 (7)5.3呼叫 (7)5.4IPS系列编程 (7)6.VIP设置命令(Telnet 远程配置) (8)6.1操作系统登录命令Telnet (8)6.2帮助命令Help (8)6.3显示配置命令Show (9)6.4设置配置命令Set (10)6.5存盘命令Save (10)6.6恢复前次配置命令Load (10)6.7恢复初始配置命令LoadDefault (10)6.8系统重起动命令Reboot (10)6.9退出命令配置Quit (11)7.配置数据 (12)7.1NetWork部分 (12)7.1.1广域网IP (12)7.1.2广域网IP子网掩码 (12)7.1.3广域网MAC值 (12)7.1.4广域网口DHCP模式 (12)7.1.5局域网IP (13)7.1.6局域网IP子网掩码 (13)7.1.7局域网MAC值 (13)7.1.8DNS状态 (13)7.1.9DNS IP (13)7.1.10默认网关IP (14)7.1.11NAT功能 (14)7.1.12NAT端口映射表 (14)7.1.13PPPoE (14)7.1.14PPPoE 用户名 ......................................... 147.1.15PPPoE 用户密码. (15)7.2GateWay部分 (15)7.2.1网关别名 (15)7.2.2网关IP (15)7.2.3网关区号 (15)7.2.4呼入前缀匹配值 (15)7.2.5呼入前缀删除状态 (16)7.2.6设备最大允许话音通道数 (16)7.2.7启用快速呼叫功能 (16)7.2.8Q.931协议端口值 (16)7.2.9RTP起始端口值 (16)7.2.10TCP起始端口值 (17)7.2.11MCC通信定时器 (17)7.2.12网守定时器 (17)7.2.13TCP定时器 (17)7.2.14ALERTING定时器 (17)7.2.15CONNECING定时器 (17)7.2.16RAS重发次数 (18)7.2.17网守状态 (18)7.2.18网守IP (18)7.2.19TUNNEL状态 (18)7.2.20网关路由表 (18)7.3CDR IP部分 (19)7.3.1中央维护台的IP (19)7.3.2普通维护台IP (19)7.3.3设置SNMP 管理站IP (19)7.4GateKeeper部分 (19)7.4.1网守最大支持呼叫数基本属性 (19)7.4.2内部网守状态 (20)7.4.3IRR消息频率 (20)7.4.4RRQ消息频率 (20)7.4.5RRQ消息超时次数 (20)7.4.6IRR消息超时次数 (20)7.4.7GKID (20)7.4.8网守信息表 (21)7.4.9DSP状态 (21)7.4.10语音编码类型 (21)7.4.11传真模式 (21)7.4.12语音包允许延迟时长 (22)7.4.13回声抵消状态 (22)7.4.14静音检测状态 (22)7.5SYSTEM部分 (22)7.5.1系统软件版本 (22)7.5.2T35国家码 (22)7.5.3T35扩展码 (22)7.5.4终端类别 (23)7.5.5产品ID号 (23)7.5.6设备厂家号 (23)7.5.7H.323协议栈版本 (23)7.5.8H.225协议栈版本 (23)7.5.9H.245协议栈版本 (23)7.6Dialedlen部分 (23)7.7IP ECHO部分 (24)7.7.1IPECHO客户端 (24)7.7.2客户机定时发送消息时间 (24)7.7.3服务器所在地址 (24)7.7.4服务器所在端口 (25)7.7.5是否作为服务器 (25)8.关于配置文件的存取 (26)8.1下载VIP配置文件至PC (26)8.2上传PC的配置文件至VIP中: (26)8.3用TFTP升级VIP系统软件 (26)9.维护注意事项 (27)9.1VIP板RUN灯长亮 (27)9.2IPS电话无法呼出 (27)图图5-1面板指示图 (5)表表5-1面板LED定义 (5)1.前言●本手册详细地介绍了IPS-1000系列V oIP综合接入系统(IPS-1016/1160/1240)的结构、工程安装说明、软件设置等,您也可以根据目录及页眉的标题进行选择性地阅读此手册。
GStreamerRTP插件的改进及应用

实时数据传输协议 RTP(Real-time Transfer Protocol) 是 IETF 为了支持网络实时传输服务而提供的数据实时传输
加密算法是使用 A E S 或不加密;使用 H M A C - S H A 1 算法保 护数据完整性;采用包索引维护算法防止重放攻击。
的标准,用于在网络上传输音频、视频等实时流媒体数据。它
(2) 衬垫(Pads):衬垫是元件与外界的连接通道,用来在 元件间协商连接和数据流,可以看作元件间互相连接的“接 口”,数据流通过这些接口流入流出元件。它具有特殊的数据 处理能力,可以限制通过它的数据类型,当两个衬垫允许通 过的数据类型兼容时才可以将它们连接起来。
(3) 数据、缓冲区和事件:GStreamer 中的所有数据流被 分割成块,从一个元件的源衬垫传到另一个元件的接收衬垫。 当前存在两种数据类型:事件和缓冲区。缓冲区可以包含两个 相连接的衬垫所能处理的任何数据。通常,一个缓冲区包含一 块音频或视频数据块,该数据块从一个元件流向另一个元件。 事件包含两个相连的衬垫间的流的状态信息,只有事件被元件 显式地支持时它们才会被发送,否则核心层将自动处理。
(4) MIME 类型和属性:GStreamer 使用一个类型系统识 别流经元件的数据格式。元件间的每一个连接有一个指定的 类型和可选的属性集。GStreamer 已支持许多基本的媒体类 型,RTP 插件的 MIME 类型为 application/x-rtp。 1.2 RTP 插件原理
RTP 插件基本原理如图 1 所示。图 1 简要描述了双工 工作时单向 VOIP 语音通信过程,其中发送音频数据流时, 关键部件为元件 pay,负责将采样、编码以后的音频数据 封装为 GstBuffer 包格式交给系统处理后通过网络传输。 接收音频数据流时,关键部件为元件 d e p a y ,完成系统通 过网络接收后的 GstBuffer数据包,解封装为音频数据,解 码后播出播放。
Ixchariot脚本详解

IxChariot™ Application ScriptsRelease 6.20909-0397 Rev. ADecember 20052IxChariot™ Application ScriptsCopyright © 1998-2005 Ixia. All rights reserved.This publication may not be copied, in whole or in part, without Ixia’s consent.RESTRICTED RIGHTS LEGEND: Use, duplication, or disclosure by the U.S. Government is subject to the restrictions set forth in subparagraph (c)(1)(ii) of the Rights in Technical Data and Computer Software clause at DFARS 252.227-7013 and FAR 52.227-19.Ixia, the Ixia logo, and all Ixia brand names and product names in this document are either trademarks or registered trademarks of Ixia in the United States and/or other countries. All other trademarks belong to their respective owners.Part No. 913-0096 Rev. ADecember 12, 2005CorporateHeadquarters 26601 W. Agoura Rd.Calabasas, CA 91302USA+1 (877) FOR IXIA (877-367-4942)+1 (818) 871 1800 (International)(FAX) +1 (818) 871-1805sales@Web site: General: info@ Investor Relations: ir@ Training: training@ Support: support@ +1 (877) 367 4942EMEA Ixia Europe LimitedAvonbury Business Park, Unit 5Howes LaneBicester, Oxfordshire, OX26 2UAUnited Kingdom+44 1869 356370(FAX) +44 1869 356371ixiaeurope@Support: eurosupport@ +44 1869 356370 (Option 5) Asia Pacific Asia Pacific Representative OfficeNew Shangai International Tower, Suite 26E360 Pudong Nan RdShanghai 200120China+86 21 50543439ixiachina@Support: support@ +1 (877) 367 4942Japan Ixia KKAioi Sampo Shinjuku Building, 16th Floor3-25-3 Yoyogi Shibuya-KuTokyo 151-0053Japan+81-3-5365-4690(FAX) +81-3-3299-6263ixiajapan@ Support: support@ +1 (877) 367 4942India No. 508, 6th Main 6th CrossST Bed, Koramangala 4th BlockBangalore 560 034India+91 80 25633570(FAX) +91 80 25633487ixiaindia@ Support: support.india@ +91 80 30918500The Messages and Application Scripts Guide provides a reference to applicationscripts and to the messages generated by the Performance and Availability prod-ucts. This book defines terminology and various related concepts.Intended AudienceThis book provides information for individuals responsible for understandingIxChariot concepts and running tests with IxChariot.Other Information in the LibraryThe IxChariot Help Library provides the following information resources:•User GuideContains comprehensive guidance for using IxChariot. This book also pro-vides an overview of the IxChariot user interfaces and Help system.•Messages and Application ScriptsExplains how to work with application scripts and includes detailed informa-tion about messages and how to avoid them.•API GuideProvides information about writing C programs or Tcl scripts to the IxChariotapplication programming interface that use and extend the capabilities ofIxChariot.•Performance EndpointsGives step-by-step guidance for installing and configuring Performance End-points for different operating systems.•HelpProvides context-sensitive information and step-by-step guidance for com-mon tasks, as well as definitions for each field on each window.IxChariot™ Application Scripts1PrefaceConventionsThe library uses consistent conventions to help you identify items throughout thedocumentation. The following table summarizes these conventions.Convention UseBold Window and menu items.Technical terms, when introduced.Italic Book and CD-ROM titles.Variable names and values.Emphasized words.Fixed Font File and folder names.Commands and code examples.Text you must type.Text (output) displayed in the command-line interface. 2IxChariot™IxChariot™ Application ScriptsChapter 1Application ScriptsWhat’s in This Guide. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-1How IxChariot Uses the Scripts. . . . . . . . . . . . . . . . . . . . . . 1-2What’s New in Version 6.20? . . . . . . . . . . . . . . . . . . . . . . . 1-3 Chapter 2Summary of the ScriptsApplication Group Files. . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2Benchmark Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-6Internet Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-10 Without Payload . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-10With Payload. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-14IRC Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-16 Login Scripts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-16Text Chat Scripts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-17 IxChariot™ Application Scripts1Table of ContentsP2P (Peer to Peer) Scripts. . . . . . . . . . . . . . . . . . . . . . . . .2-17 Kazaa . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-17eDonkey . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-18BitTorrent. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-20Voice Signaling Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . .2-22 SIP Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-22H.323 Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-25Web Push Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-28Business Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-31Streaming Scripts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-38Generic Test Scripts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-41Large Test Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-41 Chapter 3Ixia StreamsBackground Traffic Streams. . . . . . . . . . . . . . . . . . . . . . . . .3-1Denial of Service (DoS) Attack Streams . . . . . . . . . . . . . . .3-2 What are “Denial of Service Attacks”? . . . . . . . . . . . . . . . . . . . . . . .3-2IMIX Traffic Streams. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-4 Chapter 4Script Commands, Parameters, and VariablesCommunications Commands. . . . . . . . . . . . . . . . . . . . . . . .4-1 Mapping of Script Commands for Sockets . . . . . . . . . . . . . . . . . . . 4-2Mapping of Script Commands for TLI. . . . . . . . . . . . . . . . . . . . . . . 4-3DEFAULT Values for the Endpoints . . . . . . . . . . . . . . . . . . . . . . . . 4-5 Application Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-62IxChariot™ Application ScriptsIxChariot™ Application Scripts 3Table of ContentsSupported RTP Payload Types. . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-7Program Control Commands. . . . . . . . . . . . . . . . . . . . . . . . 4-8Chapter 5Rules for ScriptsOverall Script Rules. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-1Command and Parameter Rules. . . . . . . . . . . . . . . . . . . . . 5-3CONNECT and DISCONNECT . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-3SEND and RECEIVE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-3WAIT_EVENT and SIGNAL_EVENT . . . . . . . . . . . . . . . . . . . . . . . . 5-4CONFIRM_REQUEST and CONFIRM_ACKNOWLEDGE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-5START_TIMER, END_TIMER, and INCREMENT_TRANSACTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-5LOOP and END_LOOP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-5SLEEP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-5RTP_PAYLOAD_TYPE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-5Script Variable Rules. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-6Setting Sleep Times. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-6Random Distributions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5-8Setting the Send Data Rate. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-10Choosing the Datatype on the SEND Command . . . . . . . . . . . . . 5-11Summary of send_datatype options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5-12For More Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5-13Defining Send and Receive Buffers. . . . . . . . . . . . . . . . . . . . . . . . 5-13Using Random Buffer Sizes for the SEND Command. . . . . . . . . . 5-14Table of Contents4IxChariot™ Application Scripts1Application ScriptsApplication scripts are the key to measuring network performance. They modelthe real applications you use between computers in a network. IxChariot usesapplication scripts to make the same API calls to the network protocol stacks thatreal applications make, causing the protocol stacks to perform the same workinvolved in sending and receiving data that your applications perform every day.Scripts consist of commands, such as SEND and RECEIVE, and script variables,such as the size of the buffer and the type of data in each SEND, which producedifferent data flows on the network. You can alter the parameters and variablesthat control script commands and thus customize the scripts you use in testingand monitoring. This manual details each script’s components, script commands,and script variables. It also lists and describes all the scripts that ship withIxChariot, all of which are also available free on the Ixia Web site.Application scripts are generally independent of the network protocol. Thismeans the same script can be used with any network protocol supported by thePerformance Endpoints you’re using. One group of the scripts, called streamingscripts, requires a datagram (connectionless) protocol, such as IPX, RTP, orUDP. These scripts are discussed separately below.What’s in This GuideApplication Scripts includes the following sections:•Chapter 2, Summary of the ScriptsSummarizes the Library of application scripts, grouping the applicationscripts into nine categories: Benchmark Scripts, Internet Scripts, Peer-to-PeerScripts, V oice Signaling Scripts, Web Push Scripts, Business Scripts, Stream-ing Scripts, two Large Test Scripts, and three Generic Test Scripts.•Chapter 3, Ixia StreamsA description of the Ixia streams that you can use with Ixia Hardware Perfor-mance Pairs.IxChariot™ Application Scripts1-1Application Scripts1-2IxChariot™ Application Scripts 1•Chapter 4, Script Commands, Parameters, and VariablesDiscusses the various components of a script, including all the commands and variables that make up an application script. The three categories of com-mands include Communication Commands, Application Commands, and Program Control Commands.•Chapter 5, Rules for ScriptsExplains the rules governing application scripts and their variables. These are the rules enforced by the IxChariot Script Editor and the IxProfile Script Viewer.As soon as they become available, new scripts can be downloaded free from the Ixia Web site at /support/ixchariot.How IxChariot Uses the ScriptsApplication scripts are kept at the computer where you configure tests (that is, at the IxChariot Console); scripts are only delivered to the endpoints when you start a test. IxChariot uses the same application scripts, but stores them differently. In IxChariot, application scripts are stored in separate files. At installation time, these binary files are installed in the Scripts subdirectories of the directory where you installed the IxChariot Console. For example, if you installed IxChariot in D:\Program Files\Ixia\IxChariot , the script files are located in D:\Program Files\Ixia\IxChariot\Scripts and then further sorted by type, such as Business or Streaming. You may wish to put the script files on a different drive or in a different directory. If you do, you should update the Where to read script files field on the Directories tab of the Change User Settings note-book. Refer to the User Guide for IxChariot for more information.Tests in IxChariot start when you click the Run button or start RUNTST from the command line. That’s when the IxChariot Console delivers the appropriate binary script to each Endpoint 1 in the test.The user interface in IxChariot offers dialog boxes for modifying the variables in any script. In addition, you can modify existing script files or create your own script files from scratch. The Script Editor, included with IxChariot, reads and writes binary script files in the IxChariot format. If you would like to create cus-tom scripts, you can also use IxProfile to trace an application’s WinSock calls and generate a script from those calls. You can also use IxProfile to create an IxChariot script from a line trace file that was generated by a network protocol analyzer, such as Ethereal. You can then use the IxChariot Script Editor to mod-ify the scripts that you generate in IxProfile. Refer to the IxProfile User Guide for more information.Application ScriptsWhat’s New in Version 6.20?The following additions or changes have been made to the Applications Scripts in IxChariot 6.20:•Large Payload File Support in ScriptsPrior to IxChariot 6.20, a single script was limited in the number of bytes of payload data that it could contain. Beginning with release 6.20, IxChariot removes these limiations by allowing the use of external payload files that are embedded within a script or referenced from a script. Refer to Choosing the Datatype on the SEND Command on page 5-11 for details.•Enhanced send and receive buffer mechanismsIxChariot 6.20 implements two changes that improve the send and receive buffer mechanisms used in scripts:•The maximum size of the send and receive buffers used with the SENDand RECEIVE commands has been increased from 65,535 to 999,999,999.•The CONNECT_INITIATE and CONNECT_ACCEPT commands nowprovide their own send and receive buffers.Refer to Defining Send and Receive Buffers on page 5-13, CONNECT and DISCONNECT on page 5-3, and SEND and RECEIVE on page 5-3 for more information.•Pair synchronization supportPrior to release 6.20, IxChariot scripts did not provide a means to synchronize the actions of two or more pairs during a test. IxChariot 6.20 introduces the concept of an application group, which allows you to use synchronization commands within scripts. Refer to the following for details:•Application Group Files on page 2-2•Program Control Commands on page 4-8•WAIT_EVENT and SIGNAL_EVENT on page 5-4•The “Pair Synchronization Testing” topic in the IxChariot User Guide.Application Scripts 12Summary of the Scripts We ship an extensive set of application scripts with our products. We also main-tain a library of additional scripts on our Web site; they can be downloaded freeat our Web site: /support/chariot. This library of appli-cation scripts emulates applications in several categories:• A set of Ixia streams allow background traffic to emulate TCP, UDP, IP andV oIP traffic in varying frame sizes. See Ixia Streams on page 3-1.• A group of IxChariot Application Group Files, each of which emulates anapplication that employs multiple connections. Each application groupincludes two or more pairs; each pair provides its own script.• A set of scripts emulates the Bader benchmarks or classic transactions; theseBenchmark Scripts can represent almost any client/server application.• A set of Internet Scripts emulates network applications commonly availableon today’s desktop operating systems. These include scripts both with andwithout embedded payloads• A set of P2P (Peer to Peer) Scripts emulate the popular Kazaa, eDonkey andBitTorrent peer-to-peer protocols.• A set of Voice Signaling Scripts emulate the voice signaling traffic generatedby the H.323 and Session Initiation Protocol (SIP) running over TCP or UDPconnections.•Web Push Scripts are also included in the Internet scripts and emulate theflows of Internet push applications: BackWeb, by BackWeb Technologies;Castanet Tuner, by Marimba Inc.; Headliner, by Lanacom (acquired July1997 by BackWeb Technologies); and PointCast Network, by PointCast Inc.• A set of Business Scripts emulates popular business applications such asLotus Notes, SAP R/3, and Active Directory for Windows 2000.• A set of Streaming Scripts emulates multimedia applications: NetShow andNetMeeting from Microsoft, RealAudio from RealNetworks, and IP/TV fromCisco Systems. These scripts must be run over a datagram protocol: IPX,RTP, or UDP.•Two Large Test Scripts designed to emulate large tests involving 2,500 to10,000 pairs. These scripts are only available in IxChariot.Summary of the Scripts2•Three Generic Test Scripts are included for users who want to test connectiv-ity, throughput, or response time on their network.Ixia continues to add scripts that emulate well-known applications. These will beavailable in program updates and via our Web site. Contact us if you uncover sit-uations where you need a specific script that’s not available.•In IxChariot, scripts use a wide variety of default loop count values, to emu-late repeatedly running an application. The defaulttransactions_per_record values differ between long- and-short-con-nection versions of the same script (such as Creditl and Credits). This isto keep the run time of the two scripts about the same, for example, for a fewseconds on a 10 Mbps Ethernet LAN.The script filenames shown are the names by which a script can be opened andsaved in IxChariot’s Script Editor.Application Group FilesIxChariot provides a set of application group files that you can import into theIxChariot test window. To import an application group into the Test window:1.Select File > Application Group > Import.2.Select the desired application group file (.iag file).3.Click I MPORT.IxChariot application groups provide a means to synchronize the actions of mul-tiple scripts, and thereby design tests that emulate applications that employ multi-ple connections. For example, FTP operations require two connections: one forcontrol, the other for data transmission.Refer to the following for additional details about application groups:•Program Control Commands on page 4-8•WAIT_EVENT and SIGNAL_EVENT on page 5-4•The “Pair Synchronization Testing” topic in the IxChariot User Guide.The following table describes the application group files.Summary of the ScriptsApplication Group ScriptsApplication GroupFilenameApplication Script Names Descriptionactive_FTP.iag active_FTP_control.scr,active_FTP_data.scr This application group uses two pairs to emulate the two connections needed to accomplish an active FTP operation. In active mode FTP, the client connects from a random unprivileged port (N > 1024) to the FTP server's command port (port 21). Then, the client starts listening to port N+1 and sends the FTP command PORT N+1 to the FTP server. The server then connects back to the client's specified data port from its local data port (port 20). An active FTP operation involves these tasks:1.Login to the FTP server.2.Select the file to be downloaded.3.Download the file.The first pair provides the Control connection, via the active_FTP_control.scr script. The control connection is a TCP connection that emulates the login to the server and the request for the file.The second pair provides the Data connection, via the active_FTP_data.scr script. This connection emulates the file transfer.This application group uses one synchronization event, named start_transfer.BitTorrent.iag AG_BitTorrent_Contact_Tracker_PeerA.scr,AG_BitTorrent_Contact_Tracker_PeerB.scr,AG_BitTorrent_Contact_Tracker_PeerC.scr,AG_BitTorrent_Download_PeerBA.scr,AG_BitTorrent_Download_PeerAC.scr,AG_BitTorrent_Report_Statistics_PeerA.scr,AG_BitTorrent_Report_Statistics_PeerB.scr,AG_BitTorrent_Report_Statistics_PeerC.scr.This application group uses eight pairs to emulate a BitTorrent session. It simulates the traffic generated when three hosts connect to the BitTorrent tracker and start transferring data. The simulated BitTorrent session involves these tasks:1.The three hosts (A, B, and C) contract thetracker.2.Host A starts uploading a file to host B.3.While that upload is in progress, Host A alsostarts downloading a file from Host C.4.All three hosts report statistics to the tracker. This application group uses multiple synchronization events to coordinate the actions among the three hosts.Summary of the Scripts 2HTTP_streaming. iag HTTP_streaming_control.scr,HTTP_streaming_data.scrThis application group uses two pairs to emulate anHTTP session with streaming video data. TheHTTP session involves these tasks:1.Browse to a web page containing a video link.2.Select the video link.3.View the video in the player that is automaticallyopened when the link is selected.The first pair provides the Control connection, viathe HTTP_streaming_control.scr script. The controlconnection is a TCP connection that emulatesbrowsing to a web page and clicking on a video link.The second pair provides the Data connection, viathe HTTP_streaming_data.scr script. Thisconnection emulates the video streaming from theweb server to the user’s desktop.This application group uses two synchronizationevents, named start_streaming anddownload_finished.Application Group Scripts (Continued)Application GroupFilenameApplication Script Names DescriptionSummary of the Scriptspassive_FTP.iag passive_FTP_control.scr,passive_FTP_data.scr This application group uses two pairs to emulate the two connections needed to accomplish a passive FTP operation. In passive mode FTP, the client initiates both connections to the server, solving the problem of firewalls filtering the incoming data port connection to the client from the server. A passive FTP operation involves these tasks:1.Login to the FTP server.2.Select the file to be downloaded.3.Download the file.The first pair provides the Control connection, via the passive_FTP_control.scr script. The control connection is a TCP connection that emulates the login to the server and the request for the file.The second pair provides the Data connection, via the passive_FTP_data.scr script. This connection emulates the file transfer.This application group uses one synchronization event, named start_transfer.SIP_VoIP.iag SIP_Invitation_Caller_to_Proxy.scr,SIP_Invitation_Proxy_to_Callee.scr,SIP_Registration.scr This application group uses five pairs to simulate the traffic generated when a VoIP call is setup and made. The following steps are involved:1.The callee registers to the proxy server.2.The caller contacts the server to initiate the call.3.The proxy server forwards the call andannounces the caller when the callee hasanswered.4.The conversation takes place between the callerand callee.5.The caller ends the call.The first pair uses a TCP connection to emulate the dialog between the caller and the proxy.The second pair uses a TCP connection to emulate the dialog between the proxy and the callee.The third pair uses a TCP connection to emulate the callee's registration.The final pairs are the actual voice conversations. There are two pairs, one for direction.This application group uses multiple synchronization events to coordinate the call setup and call execution.Application Group Scripts (Continued) Application GroupFilenameApplication Script Names DescriptionSummary of the Scripts2Benchmark ScriptsThe benchmark scripts come in two variations: long and short connections. Youcan tell them apart by looking at the last character in the filename, which is eitheran “L” or an “S”--those with “L” use long connections, while those with “S” useshort connections. In scripts identified as long connections, a single connection isused for the entire test script, no matter how many transactions are run. The timeit takes to start and stop the connections is not included in the timings. In thoseidentified as short connections, a new connection is started for each transaction.All network protocols have overhead associated with connection startup andtake-down. Selecting the appropriate script lets you decide how much of the star-tup/take-down overhead to factor into your tests. These benchmark scripts allowyou to emulate most transaction-oriented application designs.The following tables describe the benchmark scripts.Credit Check ScriptsIxChariot Filename Application ScriptNameDescriptionCreditl.scr Credit Check, LongConnection These scripts emulate a series of credit approvals. A record is sent from Endpoint 1; Endpoint 2 receives the record and sends back a confirmation. The default record size is 100 bytes. The long connection script (Creditl) makes only one connection for the entire series of transactions in the script. The short connection script (Credits) makes a separate connection for each transaction.Credits.scr Credit Check, ShortConnectionDatabase Update ScriptsIxChariot Filename ApplicationScript NameDescriptionDbase1.scr DatabaseUpdate, LongConnection The most complex of the benchmarks. These scripts emulate a program that requests a record from Endpoint 2, receives it, updates it, and sends it back. Last, Endpoint 1 receives a confirmation that the update was completed. The default sizes for the request and the record are 100 bytes (this script can be described as an Inquiry followed by a Credit Check). The Database Update, Long Connection script makes only one connection for the entire series of transactions in the script. The Database Update, Short Connection script makes a separate connection for each transaction.Dbases.scr DatabaseUpdate, ShortConnectionSummary of the Scripts File Transfer ScriptsIxChariot Filename ApplicationScript NameDescriptionFilercvl. scr File Receive, LongconnectionEmulate requesting a file and receiving it, and sending a file and receivingan acknowledgment. The request from Endpoint 1 defaults to 100 bytes.The default file size is 100,000 bytes. The long connection scripts(Filercvl and Filesndl) make only one connection for the entire seriesof transactions in the script. The short connection scripts (Filercvs andFilesnds) make a separate connection for each transaction.Filercvs. scr File Receive, Short connectionFilesndl. scr File Send, Long ConnectionFilesnds. scr File Send, ShortConnectionHigh-Performance ThroughputIxChariot Filename Application ScriptNameDescriptionHigh_Performance _Throughput.scr High PerformanceThroughputTests maximum throughput on high-speed networks (100Mbps and higher). Sends 10,000,000 bytes fromEndpoint 1 to Endpoint 2, then waits for anacknowledgment. Instructs endpoints running onMicrosoft Windows NT, Windows 2000, and Windows XPto use overlapped I/O to achieve the highest possiblethroughput. For the most accurate results, do not edit thesend_data_rate parameter.。
H.264 RTP Payload格式

H.264的RTP负载格式1. 网络抽象层单元类型(NALU) (1)2. 打包模式 (1)3. SDP 参数 (4)1. 网络抽象层单元类型(NALU)NALU 头由一个字节组成, 它的语法如下:+---------------+|0|1|2|3|4|5|6|7|+-+-+-+-+-+-+-+-+|F|NRI| Type |+---------------+F: 1 个比特.forbidden_zero_bit. 在 H.264 规范中规定了这一位必须为 0.NRI: 2 个比特.nal_ref_idc. 取 00 ~ 11, 似乎指示这个 NALU 的重要性, 如 00 的 NALU 解码器可以丢弃它而不影响图像的回放. 不过一般情况下不太关心这个属性.Type: 5 个比特.nal_unit_type. 这个 NALU 单元的类型. 简述如下:0 没有定义1-23 NAL单元单个 NAL 单元包.24 STAP-A 单一时间的组合包24 STAP-B 单一时间的组合包26 MTAP16 多个时间的组合包27 MTAP24 多个时间的组合包28 FU-A 分片的单元29 FU-B 分片的单元30-31 没有定义2. 打包模式下面是 RFC 3550 中规定的 RTP 头的结构.0 1 2 30 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+|V=2|P|X| CC |M| PT | sequence number |+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+| timestamp |+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+| synchronization source (SSRC) identifier |+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+| contributing source (CSRC) identifiers || .... |+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+负载类型 Payload type (PT): 7 bits序列号 Sequence number (SN): 16 bits时间戳 Timestamp: 32 bitsH.264 Payload 格式定义了三种不同的基本的负载(Payload)结构. 接收端可能通过 RTP Payload的第一个字节来识别它们. 这一个字节类似 NALU 头的格式, 而这个头结构的 NAL 单元类型字段则指出了代表的是哪一种结构,这个字节的结构如下, 可以看出它和 H.264 的 NALU 头结构是一样的.+---------------+|0|1|2|3|4|5|6|7|+-+-+-+-+-+-+-+-+|F|NRI| Type |+---------------+字段 Type: 这个 RTP payload 中 NAL 单元的类型. 这个字段和 H.264 中类型字段的区别是, 当 type的值为 24 ~ 31 表示这是一个特别格式的 NAL 单元, 而 H.264 中, 只取 1~23 是有效的值.24 STAP-A 单一时间的组合包24 STAP-B 单一时间的组合包26 MTAP16 多个时间的组合包27 MTAP24 多个时间的组合包28 FU-A 分片的单元29 FU-B 分片的单元30-31 没有定义可能的结构类型分别有:1. 单一 NAL 单元模式即一个 RTP 包仅由一个完整的 NALU 组成. 这种情况下 RTP NAL 头类型字段和原始的 H.264的NALU 头类型字段是一样的.2. 组合封包模式即可能是由多个 NAL 单元组成一个 RTP 包. 分别有4种组合方式: STAP-A, STAP-B, MTAP16, MTAP24.那么这里的类型值分别是 24, 25, 26 以及 27.3. 分片封包模式用于把一个 NALU 单元封装成多个 RTP 包. 存在两种类型 FU-A 和 FU-B. 类型值分别是 28 和 29.2.1 单一 NAL 单元模式对于 NALU 的长度小于 MTU 大小的包, 一般采用单一 NAL 单元模式.对于一个原始的 H.264 NALU 单元常由 [Start Code] [NALU Header] [NALU Payload] 三部分组成, 其中 Start Code 用于标示这是一个NALU 单元的开始, 必须是 "00 00 00 01" 或 "00 00 01", NALU 头仅一个字节, 其后都是NALU 单元内容.打包时去除 "00 00 01" 或 "00 00 00 01" 的开始码, 把其他数据封包的 RTP 包即可.0 1 2 30 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+|F|NRI| type | |+-+-+-+-+-+-+-+-+ || || Bytes 2..n of a Single NAL unit || || +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+| :...OPTIONAL RTP padding |+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+如有一个 H.264 的 NALU 是这样的:[00 00 00 01 67 42 A0 1E 23 56 0E 2F ... ]这是一个序列参数集 NAL 单元. [00 00 00 01] 是四个字节的开始码, 67 是 NALU 头, 42 开始的数据是 NALU 内容.封装成 RTP 包将如下:[ RTP Header ] [ 67 42 A0 1E 23 56 0E 2F ]即只要去掉 4 个字节的开始码就可以了.2.2 组合封包模式其次, 当 NALU 的长度特别小时, 可以把几个 NALU 单元封在一个 RTP 包中.0 1 2 30 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+| RTP Header |+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+|STAP-A NAL HDR | NALU 1 Size | NALU 1 HDR |+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+| NALU 1 Data |: :+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+| | NALU 2 Size | NALU 2 HDR |+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+| NALU 2 Data |: :| +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+| :...OPTIONAL RTP padding |+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+2.3 Fragmentation Units (FUs).而当NALU 的长度超过MTU 时, 就必须对NALU 单元进行分片封包. 也称为Fragmentation Units (FUs).0 1 2 30 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+| FU indicator | FU header | |+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ || || FU payload || || +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+| :...OPTIONAL RTP padding |+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+Figure 14. RTP payload format for FU-AThe FU indicator octet has the following format:+---------------+|0|1|2|3|4|5|6|7|+-+-+-+-+-+-+-+-+|F|NRI| Type |+---------------+The FU header has the following format:+---------------+|0|1|2|3|4|5|6|7|+-+-+-+-+-+-+-+-+|S|E|R| Type |+---------------+3. SDP 参数下面描述了如何在 SDP 中表示一个 H.264 流:. "m=" 行中的媒体名必须是 "video". "a=rtpmap" 行中的编码名称必须是 "H264".. "a=rtpmap" 行中的时钟频率必须是 90000.. 其他参数都包括在 "a=fmtp" 行中.如:m=video 49170 RTP/AVP 98a=rtpmap:98 H264/90000a=fmtp:98 profile-level-id=42A01E; sprop-parameter-sets=Z0IACpZTBYmI,aMljiA== 下面介绍一些常用的参数.3.1 packetization-mode:表示支持的封包模式.当 packetization-mode 的值为 0 时或不存在时, 必须使用单一 NALU 单元模式.当 packetization-mode 的值为 1 时必须使用非交错(non-interleaved)封包模式.当 packetization-mode 的值为 2 时必须使用交错(interleaved)封包模式.这个参数不可以取其他的值.3.2 sprop-parameter-sets:这个参数可以用于传输 H.264 的序列参数集和图像参数 NAL 单元. 这个参数的值采用Base64 进行编码. 不同的参数集间用","号隔开.3.3 profile-level-id:这个参数用于指示 H.264 流的 profile 类型和级别. 由 Base16(十六进制) 表示的 3 个字节. 第一个字节表示 H.264 的 Profile 类型, 第三个字节表示 H.264 的 Profile 级别:3.4 max-mbps:这个参数的值是一个整型, 指出了每一秒最大的宏块处理速度.。
wm8960 linux codec 代码,修改过了,支持录音

* wm8960.c -- WM8960 ALSA SoC Audio driver** Copyright 2007-11 Wolfson Microelectronics, plc** Author: Liam Girdwood** This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as* published by the Free Software Foundation.*/#include <linux/module.h>#include <linux/moduleparam.h>#include <linux/init.h>#include <linux/delay.h>#include <linux/pm.h>#include <linux/i2c.h>#include <linux/slab.h>#include <sound/core.h>#include <sound/pcm.h>#include <sound/pcm_params.h>#include <sound/soc.h>#include <sound/initval.h>#include <sound/tlv.h>#include <sound/wm8960.h>#include "wm8960.h"/* R25 - Power 1 */#define WM8960_VMID_MASK 0x180#define WM8960_VREF 0x40/* R26 - Power 2 */#define WM8960_PWR2_LOUT1 0x40#define WM8960_PWR2_ROUT1 0x20#define WM8960_PWR2_OUT3 0x02/* R28 - Anti-pop 1 */#define WM8960_POBCTRL 0x80#define WM8960_BUFDCOPEN 0x10#define WM8960_BUFIOEN 0x08#define WM8960_SOFT_ST 0x04#define WM8960_HPSTBY 0x01/* R29 - Anti-pop 2 */#define WM8960_DISOP 0x40#define WM8960_DRES_MASK 0x30/** wm8960 register cache* We can't read the WM8960 register space when we are* using 2 wire for device control, so we cache them instead.*/static const u16 wm8960_reg[WM8960_CACHEREGNUM] = {0x0097, 0x0097, 0x0000, 0x0000,0x0000, 0x0008, 0x0000, 0x000a,0x01c0, 0x0000, 0x00ff, 0x00ff,0x0000, 0x0000, 0x0000, 0x0000,0x0000, 0x007b, 0x0100, 0x0032,0x0000, 0x00c3, 0x00c3, 0x01c0,0x0000, 0x0000, 0x0000, 0x0000,0x0000, 0x0000, 0x0000, 0x0000,0x0100, 0x0100, 0x0050, 0x0050,0x0050, 0x0050, 0x0000, 0x0000,0x0000, 0x0000, 0x0040, 0x0000,0x0000, 0x0050, 0x0050, 0x0000,0x0002, 0x0037, 0x004d, 0x0080,0x0008, 0x0031, 0x0026, 0x00e9,};struct wm8960_priv {enum snd_soc_control_type control_type;int (*set_bias_level)(struct snd_soc_codec *,enum snd_soc_bias_level level);struct snd_soc_dapm_widget *lout1;struct snd_soc_dapm_widget *rout1;struct snd_soc_dapm_widget *out3;bool deemph;int playback_fs;};#define wm8960_reset(c) snd_soc_write(c, WM8960_RESET, 0)/* enumerated controls */static const char *wm8960_polarity[] = {"No Inversion", "Left Inverted", "Right Inverted", "Stereo Inversion"};static const char *wm8960_3d_upper_cutoff[] = {"High", "Low"};static const char *wm8960_3d_lower_cutoff[] = {"Low", "High"};static const char *wm8960_alcfunc[] = {"Off", "Right", "Left", "Stereo"}; static const char *wm8960_alcmode[] = {"ALC", "Limiter"};static const struct soc_enum wm8960_enum[] = {SOC_ENUM_SINGLE(WM8960_DACCTL1, 5, 4, wm8960_polarity),SOC_ENUM_SINGLE(WM8960_DACCTL2, 5, 4, wm8960_polarity),SOC_ENUM_SINGLE(WM8960_3D, 6, 2, wm8960_3d_upper_cutoff),SOC_ENUM_SINGLE(WM8960_3D, 5, 2, wm8960_3d_lower_cutoff),SOC_ENUM_SINGLE(WM8960_ALC1, 7, 4, wm8960_alcfunc),SOC_ENUM_SINGLE(WM8960_ALC3, 8, 2, wm8960_alcmode),};static const int deemph_settings[] = { 0, 32000, 44100, 48000 };static int wm8960_set_deemph(struct snd_soc_codec *codec){struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);int val, i, best;/* If we're using deemphasis select the nearest available sample* rate.*/if (wm8960->deemph) {best = 1;for (i = 2; i < ARRAY_SIZE(deemph_settings); i++) {if (abs(deemph_settings[i] - wm8960->playback_fs) <abs(deemph_settings[best] - wm8960->playback_fs))best = i;}val = best << 1;} else {val = 0;}dev_dbg(codec->dev, "Set deemphasis %d\n", val);return snd_soc_update_bits(codec, WM8960_DACCTL1,0x6, val);}static int wm8960_get_deemph(struct snd_kcontrol *kcontrol,struct snd_ctl_elem_value *ucontrol){struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);ucontrol->value.enumerated.item[0] = wm8960->deemph;return 0;}static int wm8960_put_deemph(struct snd_kcontrol *kcontrol,struct snd_ctl_elem_value *ucontrol){struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);int deemph = ucontrol->value.enumerated.item[0];if (deemph > 1)return -EINVAL;wm8960->deemph = deemph;return wm8960_set_deemph(codec);}static const DECLARE_TLV_DB_SCALE(adc_tlv, -9700, 50, 0);static const DECLARE_TLV_DB_SCALE(dac_tlv, -12700, 50, 1);static const DECLARE_TLV_DB_SCALE(bypass_tlv, -2100, 300, 0);static const DECLARE_TLV_DB_SCALE(out_tlv, -12100, 100, 1);static const struct snd_kcontrol_new wm8960_snd_controls[] = {SOC_DOUBLE_R_TLV("Capture Volume", WM8960_LINVOL, WM8960_RINVOL, 0, 63, 0, adc_tlv),SOC_DOUBLE_R("Capture Volume ZC Switch", WM8960_LINVOL, WM8960_RINVOL, 6, 1, 0),SOC_DOUBLE_R("Capture Mute Switch", WM8960_LINVOL, WM8960_RINVOL, 7, 1, 0),SOC_DOUBLE_R_TLV("Playback Volume", WM8960_LDAC, WM8960_RDAC,0, 255, 0, dac_tlv),SOC_DOUBLE_R_TLV("ADC Digital Volume", WM8960_LADC, WM8960_RADC, 0, 255, 0, dac_tlv),SOC_DOUBLE_R_TLV("Headphone Playback Volume", WM8960_LOUT1, WM8960_ROUT1, 0, 127, 0, out_tlv),SOC_DOUBLE_R("Headphone Playback ZC Switch", WM8960_LOUT1, WM8960_ROUT1, 7, 1, 0),SOC_DOUBLE_R_TLV("Speaker Playback Volume", WM8960_LOUT2, WM8960_ROUT2, 0, 127, 0, out_tlv),SOC_DOUBLE_R("Speaker Playback ZC Switch", WM8960_LOUT2, WM8960_ROUT2, 7, 1, 0),SOC_SINGLE("Speaker DC Volume", WM8960_CLASSD3, 3, 5, 0),SOC_SINGLE("Speaker AC Volume", WM8960_CLASSD3, 0, 5, 0),SOC_SINGLE("PCM Playback -6dB Switch", WM8960_DACCTL1, 7, 1, 0),SOC_ENUM("ADC Polarity", wm8960_enum[0]),SOC_SINGLE("ADC High Pass Filter Switch", WM8960_DACCTL1, 0, 1, 0),SOC_ENUM("DAC Polarity", wm8960_enum[2]),SOC_SINGLE_BOOL_EXT("DAC Deemphasis Switch", 0,wm8960_get_deemph, wm8960_put_deemph),SOC_ENUM("3D Filter Upper Cut-Off", wm8960_enum[2]),SOC_ENUM("3D Filter Lower Cut-Off", wm8960_enum[3]),SOC_SINGLE("3D Volume", WM8960_3D, 1, 15, 0),SOC_SINGLE("3D Switch", WM8960_3D, 0, 1, 0),SOC_ENUM("ALC Function", wm8960_enum[4]),SOC_SINGLE("ALC Max Gain", WM8960_ALC1, 4, 7, 0),SOC_SINGLE("ALC Target", WM8960_ALC1, 0, 15, 1),SOC_SINGLE("ALC Min Gain", WM8960_ALC2, 4, 7, 0),SOC_SINGLE("ALC Hold Time", WM8960_ALC2, 0, 15, 0),SOC_ENUM("ALC Mode", wm8960_enum[5]),SOC_SINGLE("ALC Decay", WM8960_ALC3, 4, 15, 0),SOC_SINGLE("ALC Attack", WM8960_ALC3, 0, 15, 0),SOC_SINGLE("Noise Gate Threshold", WM8960_NOISEG, 3, 31, 0),SOC_SINGLE("Noise Gate Switch", WM8960_NOISEG, 0, 1, 0),SOC_DOUBLE_R("Mic Boot Gain", WM8960_LINPATH, WM8960_RINPATH, 4, 3, 0),SOC_SINGLE_TLV("Left Output Mixer Boost Bypass Volume",WM8960_BYPASS1, 4, 7, 1, bypass_tlv),SOC_SINGLE_TLV("Left Output Mixer LINPUT3 Volume",WM8960_LOUTMIX, 4, 7, 1, bypass_tlv),SOC_SINGLE_TLV("Right Output Mixer Boost Bypass Volume",WM8960_BYPASS2, 4, 7, 1, bypass_tlv),SOC_SINGLE_TLV("Right Output Mixer RINPUT3 Volume",WM8960_ROUTMIX, 4, 7, 1, bypass_tlv),//add by lyqSOC_SINGLE("MICB Switch", WM8960_POWER1, 1, 1, 0),};static const struct snd_kcontrol_new wm8960_lin_boost[] = {SOC_DAPM_SINGLE("LINPUT2 Switch", WM8960_LINPATH, 6, 1, 0),SOC_DAPM_SINGLE("LINPUT3 Switch", WM8960_LINPATH, 7, 1, 0),SOC_DAPM_SINGLE("LINPUT1 Switch", WM8960_LINPATH, 8, 1, 0),};static const struct snd_kcontrol_new wm8960_lin[] = {SOC_DAPM_SINGLE("Boost Switch", WM8960_LINPATH, 3, 1, 0),};static const struct snd_kcontrol_new wm8960_rin_boost[] = {SOC_DAPM_SINGLE("RINPUT2 Switch", WM8960_RINPATH, 6, 1, 0),SOC_DAPM_SINGLE("RINPUT3 Switch", WM8960_RINPATH, 7, 1, 0),SOC_DAPM_SINGLE("RINPUT1 Switch", WM8960_RINPATH, 8, 1, 0),};static const struct snd_kcontrol_new wm8960_rin[] = {SOC_DAPM_SINGLE("Boost Switch", WM8960_RINPATH, 3, 1, 0),};static const struct snd_kcontrol_new wm8960_loutput_mixer[] = { SOC_DAPM_SINGLE("PCM Playback Switch", WM8960_LOUTMIX, 8, 1, 0), SOC_DAPM_SINGLE("LINPUT3 Switch", WM8960_LOUTMIX, 7, 1, 0),SOC_DAPM_SINGLE("Boost Bypass Switch", WM8960_BYPASS1, 7, 1, 0), };static const struct snd_kcontrol_new wm8960_routput_mixer[] = { SOC_DAPM_SINGLE("PCM Playback Switch", WM8960_ROUTMIX, 8, 1, 0), SOC_DAPM_SINGLE("RINPUT3 Switch", WM8960_ROUTMIX, 7, 1, 0),SOC_DAPM_SINGLE("Boost Bypass Switch", WM8960_BYPASS2, 7, 1, 0), };static const struct snd_kcontrol_new wm8960_mono_out[] = {SOC_DAPM_SINGLE("Left Switch", WM8960_MONOMIX1, 7, 1, 0),SOC_DAPM_SINGLE("Right Switch", WM8960_MONOMIX2, 7, 1, 0),};static const struct snd_soc_dapm_widget wm8960_dapm_widgets[] = {SND_SOC_DAPM_INPUT("RINPUT1"),SND_SOC_DAPM_INPUT("LINPUT2"),SND_SOC_DAPM_INPUT("RINPUT2"),SND_SOC_DAPM_INPUT("LINPUT3"),SND_SOC_DAPM_INPUT("RINPUT3"),SND_SOC_DAPM_SUPPLY("MICB", WM8960_POWER1, 1, 0, NULL, 0),SND_SOC_DAPM_MIXER("Left Boost Mixer", WM8960_POWER1, 5, 0,wm8960_lin_boost, ARRAY_SIZE(wm8960_lin_boost)),SND_SOC_DAPM_MIXER("Right Boost Mixer", WM8960_POWER1, 4, 0,wm8960_rin_boost, ARRAY_SIZE(wm8960_rin_boost)),SND_SOC_DAPM_MIXER("Left Input Mixer", WM8960_POWER3, 5, 0,wm8960_lin, ARRAY_SIZE(wm8960_lin)),SND_SOC_DAPM_MIXER("Right Input Mixer", WM8960_POWER3, 4, 0,wm8960_rin, ARRAY_SIZE(wm8960_rin)),SND_SOC_DAPM_ADC("Left ADC", "Capture", WM8960_POWER1, 3, 0),SND_SOC_DAPM_ADC("Right ADC", "Capture", WM8960_POWER1, 2, 0),SND_SOC_DAPM_DAC("Left DAC", "Playback", WM8960_POWER2, 8, 0),SND_SOC_DAPM_DAC("Right DAC", "Playback", WM8960_POWER2, 7, 0),SND_SOC_DAPM_MIXER("Left Output Mixer", WM8960_POWER3, 3, 0, &wm8960_loutput_mixer[0],ARRAY_SIZE(wm8960_loutput_mixer)),SND_SOC_DAPM_MIXER("Right Output Mixer", WM8960_POWER3, 2, 0, &wm8960_routput_mixer[0],ARRAY_SIZE(wm8960_routput_mixer)),SND_SOC_DAPM_PGA("LOUT1 PGA", WM8960_POWER2, 6, 0, NULL, 0),SND_SOC_DAPM_PGA("ROUT1 PGA", WM8960_POWER2, 5, 0, NULL, 0),SND_SOC_DAPM_PGA("Left Speaker PGA", WM8960_POWER2, 4, 0, NULL, 0),SND_SOC_DAPM_PGA("Right Speaker PGA", WM8960_POWER2, 3, 0, NULL, 0),SND_SOC_DAPM_PGA("Right Speaker Output", WM8960_CLASSD1, 7, 0, NULL, 0), SND_SOC_DAPM_PGA("Left Speaker Output", WM8960_CLASSD1, 6, 0, NULL, 0),SND_SOC_DAPM_OUTPUT("SPK_LP"),SND_SOC_DAPM_OUTPUT("SPK_LN"),SND_SOC_DAPM_OUTPUT("HP_L"),SND_SOC_DAPM_OUTPUT("SPK_RP"),SND_SOC_DAPM_OUTPUT("SPK_RN"),SND_SOC_DAPM_OUTPUT("OUT3"),};static const struct snd_soc_dapm_widget wm8960_dapm_widgets_out3[] = { SND_SOC_DAPM_MIXER("Mono Output Mixer", WM8960_POWER2, 1, 0, &wm8960_mono_out[0],ARRAY_SIZE(wm8960_mono_out)),};/* Represent OUT3 as a PGA so that it gets turned on with LOUT1/ROUT1 */ static const struct snd_soc_dapm_widget wm8960_dapm_widgets_capless[] = { SND_SOC_DAPM_PGA("OUT3 VMID", WM8960_POWER2, 1, 0, NULL, 0),};static const struct snd_soc_dapm_route audio_paths[] = {{ "Left Boost Mixer", "LINPUT1 Switch", "LINPUT1" },{ "Left Boost Mixer", "LINPUT2 Switch", "LINPUT2" },{ "Left Boost Mixer", "LINPUT3 Switch", "LINPUT3" },{ "Left Input Mixer", "Boost Switch", "Left Boost Mixer", },{ "Left Input Mixer", NULL, "LINPUT1", }, /* Really Boost Switch */ { "Left Input Mixer", NULL, "LINPUT2" },{ "Left Input Mixer", NULL, "LINPUT3" },{ "Right Boost Mixer", "RINPUT1 Switch", "RINPUT1" },{ "Right Boost Mixer", "RINPUT2 Switch", "RINPUT2" },{ "Right Boost Mixer", "RINPUT3 Switch", "RINPUT3" },{ "Right Input Mixer", "Boost Switch", "Right Boost Mixer", },{ "Right Input Mixer", NULL, "RINPUT1", }, /* Really Boost Switch */ { "Right Input Mixer", NULL, "RINPUT2" },{ "Right Input Mixer", NULL, "LINPUT3" },{ "Left ADC", NULL, "Left Input Mixer" },{ "Right ADC", NULL, "Right Input Mixer" },{ "Left Output Mixer", "LINPUT3 Switch", "LINPUT3" },{ "Left Output Mixer", "Boost Bypass Switch", "Left Boost Mixer"} , { "Left Output Mixer", "PCM Playback Switch", "Left DAC" },{ "Right Output Mixer", "RINPUT3 Switch", "RINPUT3" },{ "Right Output Mixer", "Boost Bypass Switch", "Right Boost Mixer" } , { "Right Output Mixer", "PCM Playback Switch", "Right DAC" },{ "LOUT1 PGA", NULL, "Left Output Mixer" },{ "ROUT1 PGA", NULL, "Right Output Mixer" },{ "HP_L", NULL, "LOUT1 PGA" },{ "HP_R", NULL, "ROUT1 PGA" },{ "Left Speaker PGA", NULL, "Left Output Mixer" },{ "Right Speaker PGA", NULL, "Right Output Mixer" },{ "Left Speaker Output", NULL, "Left Speaker PGA" },{ "Right Speaker Output", NULL, "Right Speaker PGA" },{ "SPK_LN", NULL, "Left Speaker Output" },{ "SPK_LP", NULL, "Left Speaker Output" },{ "SPK_RN", NULL, "Right Speaker Output" },{ "SPK_RP", NULL, "Right Speaker Output" },};static const struct snd_soc_dapm_route audio_paths_out3[] = { { "Mono Output Mixer", "Left Switch", "Left Output Mixer" },{ "Mono Output Mixer", "Right Switch", "Right Output Mixer" },{ "OUT3", NULL, "Mono Output Mixer", }};static const struct snd_soc_dapm_route audio_paths_capless[] = { { "HP_L", NULL, "OUT3 VMID" },{ "HP_R", NULL, "OUT3 VMID" },{ "OUT3 VMID", NULL, "Left Output Mixer" },{ "OUT3 VMID", NULL, "Right Output Mixer" },};static int wm8960_add_widgets(struct snd_soc_codec *codec){struct wm8960_data *pdata = codec->dev->platform_data;struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);struct snd_soc_dapm_context *dapm = &codec->dapm;struct snd_soc_dapm_widget *w;snd_soc_dapm_new_controls(dapm, wm8960_dapm_widgets,ARRAY_SIZE(wm8960_dapm_widgets));snd_soc_dapm_add_routes(dapm, audio_paths, ARRAY_SIZE(audio_paths));/* In capless mode OUT3 is used to provide VMID for the* headphone outputs, otherwise it is used as a mono mixer.*/if (pdata && pdata->capless) {snd_soc_dapm_new_controls(dapm, wm8960_dapm_widgets_capless,ARRAY_SIZE(wm8960_dapm_widgets_capless));snd_soc_dapm_add_routes(dapm, audio_paths_capless,ARRAY_SIZE(audio_paths_capless));} else {snd_soc_dapm_new_controls(dapm, wm8960_dapm_widgets_out3,ARRAY_SIZE(wm8960_dapm_widgets_out3));snd_soc_dapm_add_routes(dapm, audio_paths_out3,ARRAY_SIZE(audio_paths_out3));}/* We need to power up the headphone output stage out of* sequence for capless mode. To save scanning the widget* list each time to find the desired power state do so now* and save the result.*/list_for_each_entry(w, &codec->card->widgets, list) {if (w->dapm != &codec->dapm)continue;if (strcmp(w->name, "LOUT1 PGA") == 0)wm8960->lout1 = w;if (strcmp(w->name, "ROUT1 PGA") == 0)wm8960->rout1 = w;if (strcmp(w->name, "OUT3 VMID") == 0)wm8960->out3 = w;}return 0;}static int wm8960_set_dai_fmt(struct snd_soc_dai *codec_dai,unsigned int fmt){struct snd_soc_codec *codec = codec_dai->codec;u16 iface = 0;/* set master/slave audio interface */ switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { case SND_SOC_DAIFMT_CBM_CFM:iface |= 0x0040;break;case SND_SOC_DAIFMT_CBS_CFS:break;default:return -EINVAL;}/* interface format */switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { case SND_SOC_DAIFMT_I2S:iface |= 0x0002;break;case SND_SOC_DAIFMT_RIGHT_J:break;case SND_SOC_DAIFMT_LEFT_J:iface |= 0x0001;break;case SND_SOC_DAIFMT_DSP_A:iface |= 0x0003;break;case SND_SOC_DAIFMT_DSP_B:iface |= 0x0013;break;default:return -EINVAL;}/* clock inversion */switch (fmt & SND_SOC_DAIFMT_INV_MASK) { case SND_SOC_DAIFMT_NB_NF:break;case SND_SOC_DAIFMT_IB_IF:iface |= 0x0090;break;case SND_SOC_DAIFMT_IB_NF:iface |= 0x0080;break;case SND_SOC_DAIFMT_NB_IF:iface |= 0x0010;break;default:return -EINVAL;}/* set iface */snd_soc_write(codec, WM8960_IFACE1, iface);return 0;}static struct {int rate;unsigned int val;} alc_rates[] = {{ 48000, 0 },{ 44100, 0 },{ 32000, 1 },{ 22050, 2 },{ 24000, 2 },{ 16000, 3 },{ 11250, 4 },{ 12000, 4 },{ 8000, 5 },};static int wm8960_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params,struct snd_soc_dai *dai){struct snd_soc_codec *codec = dai->codec;struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);u16 iface = snd_soc_read(codec, WM8960_IFACE1) & 0xfff3;int i;/* bit size */switch (params_format(params)) {case SNDRV_PCM_FORMAT_S16_LE:break;case SNDRV_PCM_FORMAT_S20_3LE:iface |= 0x0004;break;case SNDRV_PCM_FORMAT_S24_LE:iface |= 0x0008;break;}/* Update filters for the new rate */if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {wm8960->playback_fs = params_rate(params);wm8960_set_deemph(codec);} else {for (i = 0; i < ARRAY_SIZE(alc_rates); i++)if (alc_rates[i].rate == params_rate(params))snd_soc_update_bits(codec,WM8960_ADDCTL3, 0x7,alc_rates[i].val);}/* set iface */snd_soc_write(codec, WM8960_IFACE1, iface);return 0;}static int wm8960_mute(struct snd_soc_dai *dai, int mute){struct snd_soc_codec *codec = dai->codec;if (mute)snd_soc_update_bits(codec, WM8960_DACCTL1, 0x8, 0x8);elsesnd_soc_update_bits(codec, WM8960_DACCTL1, 0x8, 0);return 0;}static int wm8960_set_bias_level_out3(struct snd_soc_codec *codec, enum snd_soc_bias_level level){switch (level) {case SND_SOC_BIAS_ON:break;case SND_SOC_BIAS_PREPARE:/* Set VMID to 2x50k */snd_soc_update_bits(codec, WM8960_POWER1, 0x180, 0x80);break;case SND_SOC_BIAS_STANDBY:if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {snd_soc_cache_sync(codec);/* Enable anti-pop features */snd_soc_write(codec, WM8960_APOP1,WM8960_POBCTRL | WM8960_SOFT_ST |WM8960_BUFDCOPEN | WM8960_BUFIOEN);/* Enable & ramp VMID at 2x50k */snd_soc_update_bits(codec, WM8960_POWER1, 0x80, 0x80);msleep(100);/* Enable VREF */snd_soc_update_bits(codec, WM8960_POWER1, WM8960_VREF,WM8960_VREF);/* Disable anti-pop features */snd_soc_write(codec, WM8960_APOP1, WM8960_BUFIOEN);}/* Set VMID to 2x250k */snd_soc_update_bits(codec, WM8960_POWER1, 0x180, 0x100);break;case SND_SOC_BIAS_OFF:/* Enable anti-pop features */snd_soc_write(codec, WM8960_APOP1,WM8960_POBCTRL | WM8960_SOFT_ST |WM8960_BUFDCOPEN | WM8960_BUFIOEN);/* Disable VMID and VREF, let them discharge */snd_soc_write(codec, WM8960_POWER1, 0);msleep(600);break;}codec->dapm.bias_level = level;return 0;}static int wm8960_set_bias_level_capless(struct snd_soc_codec *codec,enum snd_soc_bias_level level){struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec); int reg;switch (level) {case SND_SOC_BIAS_ON:break;case SND_SOC_BIAS_PREPARE:switch (codec->dapm.bias_level) {case SND_SOC_BIAS_STANDBY:/* Enable anti pop mode */snd_soc_update_bits(codec, WM8960_APOP1,WM8960_POBCTRL | WM8960_SOFT_ST |WM8960_BUFDCOPEN,WM8960_POBCTRL | WM8960_SOFT_ST |WM8960_BUFDCOPEN);/* Enable LOUT1, ROUT1 and OUT3 if they're enabled */reg = 0;if (wm8960->lout1 && wm8960->lout1->power)reg |= WM8960_PWR2_LOUT1;if (wm8960->rout1 && wm8960->rout1->power)reg |= WM8960_PWR2_ROUT1;if (wm8960->out3 && wm8960->out3->power)reg |= WM8960_PWR2_OUT3;snd_soc_update_bits(codec, WM8960_POWER2,WM8960_PWR2_LOUT1 |WM8960_PWR2_ROUT1 |WM8960_PWR2_OUT3, reg);/* Enable VMID at 2*50k */snd_soc_update_bits(codec, WM8960_POWER1,WM8960_VMID_MASK, 0x80);/* Ramp */msleep(100);/* Enable VREF */snd_soc_update_bits(codec, WM8960_POWER1,WM8960_VREF, WM8960_VREF);msleep(100);break;case SND_SOC_BIAS_ON:/* Enable anti-pop mode */snd_soc_update_bits(codec, WM8960_APOP1,WM8960_POBCTRL | WM8960_SOFT_ST |WM8960_BUFDCOPEN,WM8960_POBCTRL | WM8960_SOFT_ST |WM8960_BUFDCOPEN);/* Disable VMID and VREF */snd_soc_update_bits(codec, WM8960_POWER1,WM8960_VREF | WM8960_VMID_MASK, 0);break;case SND_SOC_BIAS_OFF:snd_soc_cache_sync(codec);break;default:break;}break;case SND_SOC_BIAS_STANDBY:switch (codec->dapm.bias_level) {case SND_SOC_BIAS_PREPARE:/* Disable HP discharge */snd_soc_update_bits(codec, WM8960_APOP2,WM8960_DISOP | WM8960_DRES_MASK,0);/* Disable anti-pop features */snd_soc_update_bits(codec, WM8960_APOP1,WM8960_POBCTRL | WM8960_SOFT_ST |WM8960_BUFDCOPEN,WM8960_POBCTRL | WM8960_SOFT_ST |WM8960_BUFDCOPEN);break;default:break;}break;case SND_SOC_BIAS_OFF:break;}codec->dapm.bias_level = level;return 0;}/* PLL divisors */struct _pll_div {u32 pre_div:1;u32 n:4;u32 k:24;};/* The size in bits of the pll divide multiplied by 10* to allow rounding later */#define FIXED_PLL_SIZE ((1 << 24) * 10)static int pll_factors(unsigned int source, unsigned int target, struct _pll_div *pll_div){unsigned long long Kpart;unsigned int K, Ndiv, Nmod;pr_debug("WM8960 PLL: setting %dHz->%dHz\n", source, target);/* Scale up target to PLL operating frequency */target *= 4;Ndiv = target / source;if (Ndiv < 6) {source >>= 1;pll_div->pre_div = 1;Ndiv = target / source;} elsepll_div->pre_div = 0;if ((Ndiv < 6) || (Ndiv > 12)) {pr_err("WM8960 PLL: Unsupported N=%d\n", Ndiv);return -EINVAL;}pll_div->n = Ndiv;Nmod = target % source;Kpart = FIXED_PLL_SIZE * (long long)Nmod;do_div(Kpart, source);K = Kpart & 0xFFFFFFFF;/* Check if we need to round */if ((K % 10) >= 5)K += 5;/* Move down to proper range now rounding is done */K /= 10;pll_div->k = K;pr_debug("WM8960 PLL: N=%x K=%x pre_div=%d\n",pll_div->n, pll_div->k, pll_div->pre_div);return 0;}static int wm8960_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id, int source, unsigned int freq_in, unsigned int freq_out){struct snd_soc_codec *codec = codec_dai->codec;u16 reg;static struct _pll_div pll_div;int ret;if (freq_in && freq_out) {ret = pll_factors(freq_in, freq_out, &pll_div);if (ret != 0)return ret;}/* Disable the PLL: even if we are changing the frequency the* PLL needs to be disabled while we do so. */snd_soc_update_bits(codec, WM8960_CLOCK1, 0x1, 0);snd_soc_update_bits(codec, WM8960_POWER2, 0x1, 0);if (!freq_in || !freq_out)return 0;reg = snd_soc_read(codec, WM8960_PLL1) & ~0x3f;reg |= pll_div.pre_div << 4;reg |= pll_div.n;if (pll_div.k) {reg |= 0x20;snd_soc_write(codec, WM8960_PLL2, (pll_div.k >> 18) & 0x3f);snd_soc_write(codec, WM8960_PLL3, (pll_div.k >> 9) & 0x1ff);snd_soc_write(codec, WM8960_PLL4, pll_div.k & 0x1ff);}snd_soc_write(codec, WM8960_PLL1, reg);/* Turn it on */snd_soc_update_bits(codec, WM8960_POWER2, 0x1, 0x1);msleep(250);snd_soc_update_bits(codec, WM8960_CLOCK1, 0x1, 0x1);return 0;}static int wm8960_set_dai_clkdiv(struct snd_soc_dai *codec_dai, int div_id, int div){struct snd_soc_codec *codec = codec_dai->codec;u16 reg;switch (div_id) {case WM8960_SYSCLKDIV:reg = snd_soc_read(codec, WM8960_CLOCK1) & 0x1f9;snd_soc_write(codec, WM8960_CLOCK1, reg | div);break;case WM8960_DACDIV:reg = snd_soc_read(codec, WM8960_CLOCK1) & 0x1c7;snd_soc_write(codec, WM8960_CLOCK1, reg | div);break;case WM8960_OPCLKDIV:reg = snd_soc_read(codec, WM8960_PLL1) & 0x03f;snd_soc_write(codec, WM8960_PLL1, reg | div);break;case WM8960_DCLKDIV:reg = snd_soc_read(codec, WM8960_CLOCK2) & 0x03f;snd_soc_write(codec, WM8960_CLOCK2, reg | div);break;case WM8960_TOCLKSEL:reg = snd_soc_read(codec, WM8960_ADDCTL1) & 0x1fd;snd_soc_write(codec, WM8960_ADDCTL1, reg | div);break;default:return -EINVAL;}return 0;}static int wm8960_set_bias_level(struct snd_soc_codec *codec,enum snd_soc_bias_level level){struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);return wm8960->set_bias_level(codec, level);}#define WM8960_RATES SNDRV_PCM_RATE_8000_48000#define WM8960_FORMATS \(SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \SNDRV_PCM_FMTBIT_S24_LE)static const struct snd_soc_dai_ops wm8960_dai_ops = { .hw_params = wm8960_hw_params,.digital_mute = wm8960_mute,.set_fmt = wm8960_set_dai_fmt,.set_clkdiv = wm8960_set_dai_clkdiv,.set_pll = wm8960_set_dai_pll,};static struct snd_soc_dai_driver wm8960_dai = {.name = "wm8960-hifi",.playback = {.stream_name = "Playback",.channels_min = 1,.channels_max = 2,.rates = WM8960_RATES,.formats = WM8960_FORMATS,},.capture = {.stream_name = "Capture",.channels_min = 1,.channels_max = 2,.rates = WM8960_RATES,.formats = WM8960_FORMATS,},.ops = &wm8960_dai_ops,.symmetric_rates = 1,};static int wm8960_suspend(struct snd_soc_codec *codec){struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);wm8960->set_bias_level(codec, SND_SOC_BIAS_OFF);return 0;}static int wm8960_resume(struct snd_soc_codec *codec){struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);wm8960->set_bias_level(codec, SND_SOC_BIAS_STANDBY);return 0;}static int wm8960_probe(struct snd_soc_codec *codec){struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);struct wm8960_data *pdata = dev_get_platdata(codec->dev);int ret;wm8960->set_bias_level = wm8960_set_bias_level_out3;if (!pdata) {dev_warn(codec->dev, "No platform data supplied\n");} else {if (pdata->dres > WM8960_DRES_MAX) {dev_err(codec->dev, "Invalid DRES: %d\n", pdata->dres);pdata->dres = 0;}if (pdata->capless)wm8960->set_bias_level = wm8960_set_bias_level_capless;}ret = snd_soc_codec_set_cache_io(codec, 7, 9, wm8960->control_type);if (ret < 0) {。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
RTP Payload Format for DRA AudioAbstract本文档描述了一种使用RTP协议传输DRA压缩音频数据时的打包方案,以及相应的RTP 载荷格式。
根据DRA压缩音频帧以及网络MTU(最大传输字节)的特性,该方案提供了三种打包模式,以适应不同层次的编码及传输需求。
本文档为临时文本,在相关组织颁布正式文本后将被废弃。
1.IntroductionDRA多声道数字音频编解码技术可在有限容量的存储介质或有限带宽的信道上保存或传送高质量的多声道数字音频信号,适用于各种数字音频广播、数字电视伴音、家庭影院、网络流媒体以及个人媒体播放器等应用领域。
在IP网络传输及实时播放等应用中,可使用Real-Time Transport Protocol(RTP)[1] 来传输和同步DRA音频流。
本文档第二节对DRA算法作了一个简单的介绍。
第三节详细说明了DRA打包方案,以及载荷格式。
2.Overview of DRADRA数字音频编解码技术在各信号通道均可保持24 bits的精度(除了因量化而有意舍弃的精度外)。
可支持的声道设置除了常见的立体声、5.1环绕声、6.1环绕声和7.1环绕声之外,还为未来的音频技术发展预留了空间(最多可支持64.3环绕声)。
DRA可支持从8 kHz 到192 kHz间的标准采样频率,包括44.1 KHz和48 KHz。
DRA对编码比特率(码率)没有明确限制,在具体应用时可根据信道带宽和音质要求等因素来设定。
DRA在编码时固定以1024个样本为一帧进行编码,这样每帧对应的持续时间可根据采样率计算得出。
编码后的压缩帧长度根据编码参数的设定而不同,可根据帧头中音频数据帧长信息 [2] 得出。
图1给出了DRA的帧结构。
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 同步字 | 帧头 | 正常声道音频数据 | 低频效应声道音频数据 | 误码检测 | 辅助数据 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+图1. DRA帧结构每个音频帧以同步字(0x7fff)开始,紧接同步字为帧头信息,以提供当前音频帧的相关信息。
图2给出了部分帧头结构。
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 帧头类型 | 音频数据帧长 | 其它帧头信息 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+图2. DRA帧头结构帧头类型:1bit。
“0”表示当前帧头为常规帧头,“1”表示为扩展帧头。
音频数据帧长:10bits(常规帧头)或13bits(扩展帧头)。
指示当前帧的音频数据从同步字(第一个字节)开始一直到误码检测字结束的长度,以32比特为单位。
该信息占用的比特数由帧头类型决定。
3.RTP Payload FormatDRA编码器产生的压缩帧帧长根据不同的采样率及比特率设定而不同,在高码率编码模式下,帧长可能超出网络MTU(最大传输字节)的限制,这时在使用RTP传输时,需要对单个音频帧进行分块。
DRA同时支持可变码率(VBR)编码,根据音频信息丰富的程度为每帧分配比特资源;传输时为提高网络传输效率,在MTU允许的情况下,可使用一个RTP包承载多个占用很少帧长的连续音频帧。
RTP DRA载荷格式可使用以下三种打包模式:Single-Frame Packet:RTP载荷包含单个完整的DRA压缩帧。
Multi-Frame Packet:RTP载荷包含多个完整的DRA压缩帧。
Frag-Frame Packet:RTP载荷包含单个DRA压缩帧的一个分块。
3.2对三种模式进行了详细说明。
3.1 RTP Header UsageRFC 3550 [1] 规定了RTP头(RTP Header)的格式,本文档按照此规定使用RTP头中各信息。
为方便起见,图3重新给出了RTP头的格式。
0 1 2 30 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+|V=2|P|X| CC |M| PT | sequence number |+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+| timestamp |+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+| synchronization source (SSRC) identifier |+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+| contributing source (CSRC) identifiers || .... |+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+图3. RTP header according to RFC3550Marker bit(M):1 bit该位被置“1”时,说明当前RTP包中包含至少一个完整的音频帧,或当前RTP包承载音频帧的最后一个分块。
Payload type(PT,载荷类型):7 bits对DRA RTP packet载荷类型的分配不在本文档的范围之内,它由使用DRA RTP payload format的RTP profile指定,或者动态指定。
TimeStamp(timestamp,时间戳):32bitsRTP时间戳用来指示该RTP包中第一个音频帧的采样时间。
对于DRA RTP payload,时间戳对应的时钟频率等于音频采样频率。
如果当前RTP包中包含多个DRA音频帧,每个音频帧的采样时间可由该时间戳线性累加音频帧的持续时间计算得出。
在分块模式(Frag-Frame Packet)下,属于同一个音频帧的RTP包应具有相同的时间戳。
3.2 Structure of the RTP DRA Payload Format载荷由16 bits长的载荷头(payload header)和音频帧数据共同组成,对于三 RTPDRA种打包模式,载荷中所不同的只是音频帧数据的组成。
图4给出了Multi-Frame Packet模式下的载荷结构。
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Payload Header | DRA帧1 | DRA帧2 | DRA帧3 | ... | DRA帧n | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+图4. Multi-Frame Packet RTP载荷结构载荷头的结构如图5所示。
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+|PM | MBZ | N |+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+图5. RTP载荷头结构Packetization Mode(PM,打包模式):2 bits指示当前RTP包的打包模式,该信息每个值对应的模式如下:表1. 打包模式PM value Mode------------------------------------------------------------0 Single-Frame Packet1 Multi-Frame Packet2 Frag-Frame Packet3 Forbidden,禁止出现该值Must Be Zero(MBZ,保留):6 bits将来扩展应用的保留位,该6个比特须全部置“0”。
Number(N,块序号或帧数):8 bits如果PM值为“1”,即Multi-Frame Packet模式时,Number为该RTP包中包含的DRA 音频帧数;PM值为“2”时,表示当前RTP包承载的是音频帧中第Number个分块;Single-Frame Packet模式下Number值为“1”。
4.References4.1Normative References[1] Schulzrinne, H., Casner, S., Frederick, R., and V.Jacobson, "RTP: A Transport Protocolfor Real-Time Applications", STD 64, RFC 3550, July 2003.[2] 游余立,张尉雄,徐茂,张素兵,“多声道数字音频编解码技术规范”,SJ/T11368-2006,2007年1月。
4.2Informative References[3] Handley, M. and C. Perkins, "Guidelines for Writers of RTP Payload FormatSpecifications", BCP 36, RFC 2736,December 1999.[4] B. Link, T. Hager, and J. Flaks, "RTP Payload Format for AC-3 Audio", RFC4184,October 2005.。