[go: up one dir, main page]

CN114339378A - Audio and video code stream processing method and device and electronic equipment - Google Patents

Audio and video code stream processing method and device and electronic equipment Download PDF

Info

Publication number
CN114339378A
CN114339378A CN202111587352.8A CN202111587352A CN114339378A CN 114339378 A CN114339378 A CN 114339378A CN 202111587352 A CN202111587352 A CN 202111587352A CN 114339378 A CN114339378 A CN 114339378A
Authority
CN
China
Prior art keywords
audio
buffer
video
code
physical address
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202111587352.8A
Other languages
Chinese (zh)
Other versions
CN114339378B (en
Inventor
陆子海
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Spreadtrum Communications Shanghai Co Ltd
Original Assignee
Spreadtrum Communications Shanghai Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Spreadtrum Communications Shanghai Co Ltd filed Critical Spreadtrum Communications Shanghai Co Ltd
Priority to CN202111587352.8A priority Critical patent/CN114339378B/en
Publication of CN114339378A publication Critical patent/CN114339378A/en
Application granted granted Critical
Publication of CN114339378B publication Critical patent/CN114339378B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Compression Or Coding Systems Of Tv Signals (AREA)

Abstract

本发明实施例提供了一种音视频码流的处理方法、装置和电子设备。该方法包括:根据接收到的信号,生成传输流,从传输流中过滤出音视频码流,所述音视频码流包括打包的基本码流PES数据,将所述PES数据写入内存的多个环形缓冲中,所述PES数据包括至少一个起始码,对所述至少一个起始码在所述多个环形缓冲的位置进行识别,得到所述位置对应的物理地址,将所述物理地址记录到所述内存的起始码缓冲区中,响应于生成的中断通知信号,根据所述物理地址对所述PES数据进行解析生成压缩音视频帧,并将所述压缩音视频帧写入到所述内存中的至少一个帧缓冲区中。本发明实施例减少了延时较长引起的丢帧卡顿。

Figure 202111587352

Embodiments of the present invention provide a method, an apparatus, and an electronic device for processing audio and video code streams. The method includes: generating a transport stream according to the received signal, filtering out an audio and video code stream from the transport stream, the audio and video code stream including the packaged elementary code stream PES data, and writing the PES data into a multi-level memory of the memory. In the ring buffers, the PES data includes at least one start code, the position of the at least one start code in the plurality of ring buffers is identified, the physical address corresponding to the position is obtained, and the physical address is Recorded in the start code buffer of the memory, in response to the generated interrupt notification signal, parse the PES data according to the physical address to generate a compressed audio and video frame, and write the compressed audio and video frame into the in at least one frame buffer in the memory. The embodiment of the present invention reduces frame loss and jamming caused by long delay.

Figure 202111587352

Description

一种音视频码流的处理方法、装置和电子设备A method, device and electronic device for processing audio and video code streams

【技术领域】【Technical field】

本发明涉及电视领域,具体涉及一种音视频码流的处理方法、装置和电子设备。The present invention relates to the field of television, in particular to a method, device and electronic device for processing audio and video code streams.

【背景技术】【Background technique】

目前,电视直播中对音视频码流的处理方法主流是将接收到的信号经过处理后输出传输流,解复用(Demultiplexer,Demux)硬件根据驱动软件设置的包标识符(PacketIdentifier,PID)值过滤出传输流中的打包的基本码流(Packet Elementary Stream,PES)数据,并将PES数据写入驱动软件为硬件分配的缓冲区中,通过驱动软件读取缓冲区中的数据逐字节解析,并进行组帧操作,将组帧完成的压缩音视频帧拷贝到上层用户空间。At present, the mainstream method of processing audio and video streams in live TV is to process the received signal and then output the transport stream. The demultiplexer (Demux) hardware is based on the PacketIdentifier (PID) value set by the driver software. Filter out the Packet Elementary Stream (PES) data in the transport stream, write the PES data into the buffer allocated by the driver software for the hardware, and parse the data in the buffer byte by byte through the driver software , and perform the framing operation to copy the compressed audio and video frames completed by framing to the upper-layer user space.

驱动软件为各厂商私有并进行实现,根据Android S平台google DTV Hal层参考代码,对压缩音视频帧的解析过程中会出现多次拷贝操作,数据会在内核与上层用户空间频繁传输,并会消耗大量内存。The driver software is private and implemented by each manufacturer. According to the reference code of the google DTV Hal layer of the Android S platform, there will be multiple copy operations during the parsing process of compressed audio and video frames, and the data will be frequently transmitted in the kernel and upper user space, and will consumes a lot of memory.

然而,解析PES数据时逐字节解析并进行组帧操作,会因为组帧效率太低导致播放器在播放高分辨率码流时产生卡顿的问题,无法保障电视节目的流畅播放。通过驱动软件将组帧完成的压缩音视频帧拷贝到上层用户空间会导致系统性能降低。However, when parsing PES data byte-by-byte parsing and framing operation will cause the player to freeze when playing high-resolution code streams because the framing efficiency is too low, and the smooth playback of TV programs cannot be guaranteed. Copying the compressed audio and video frames completed by framing to the upper user space through the driver software will reduce the system performance.

【发明内容】[Content of the invention]

有鉴于此,本发明实施例提供了音视频码流的处理方法、装置和电子设备与存储介质,用以解决现有技术中拷贝压缩音视频帧导致的系统性能降低、组帧速度低和延时较长导致的丢帧卡顿的问题。In view of this, the embodiments of the present invention provide a processing method, device, electronic device and storage medium for audio and video code streams, so as to solve the system performance degradation, low frame rate and delay caused by copying and compressing audio and video frames in the prior art. The problem of frame dropping and freezing caused by a long time.

一方面,本发明提供了一种音视频码流的处理方法,所述方法包括:In one aspect, the present invention provides a method for processing audio and video streams, the method comprising:

根据接收到的信号,生成传输流;Generate a transport stream according to the received signal;

从传输流中过滤出音视频码流,所述音视频码流包括打包的基本码流PES数据;Filter out the audio and video code stream from the transport stream, and the audio and video code stream includes the packaged elementary code stream PES data;

将所述PES数据写入内存的多个环形缓冲中,所述PES数据包括至少一个起始码;Writing the PES data into a plurality of ring buffers in the memory, the PES data including at least one start code;

对所述至少一个起始码在所述多个环形缓冲的位置进行识别,得到所述位置对应的物理地址;Identifying the position of the at least one start code in the plurality of ring buffers to obtain a physical address corresponding to the position;

将所述物理地址记录到所述内存的起始码缓冲区中;recording the physical address in the start code buffer of the memory;

响应于生成的中断通知信号,根据所述物理地址对所述PES数据进行解析生成压缩音视频帧,并将所述压缩音视频帧写入到所述内存中的至少一个帧缓冲区中。In response to the generated interrupt notification signal, the PES data is parsed according to the physical address to generate a compressed audio and video frame, and the compressed audio and video frame is written into at least one frame buffer in the memory.

可选的,所述从传输流中过滤出音视频码流,包括:Optionally, the filtering out the audio and video streams from the transport stream includes:

通过设置的包标识符PID对所述传输流进行过滤,生成所述音视频码流。Filter the transport stream through the set packet identifier PID to generate the audio and video stream.

可选的,所述响应于生成的中断通知信号,根据所述物理地址对所述PES数据进行解析生成压缩音视频帧之前,还包括:Optionally, before the PES data is parsed according to the physical address to generate a compressed audio and video frame in response to the generated interrupt notification signal, the method further includes:

对所述至少一个起始码在所述多个环形缓冲的个数进行识别,生成每个所述环形缓冲对应的所述起始码的个数;Identifying the number of the at least one start code in the plurality of ring buffers, and generating the number of the start codes corresponding to each of the ring buffers;

将所述起始码的个数记录到对应的所述环形缓冲中。Record the number of the start codes into the corresponding ring buffer.

可选的,将所述物理地址记录到内存的起始码缓冲区中之前,还包括:Optionally, before recording the physical address in the start code buffer of the memory, the method further includes:

分配一个指定大小的缓冲区,将所述指定大小的缓冲区作为所述起始码缓冲区。Allocate a buffer of a specified size, and use the buffer of the specified size as the start code buffer.

可选的,所述将所述压缩音视频帧写入到内存中的至少一个帧缓冲区中,包括:Optionally, the writing of the compressed audio and video frames into at least one frame buffer in the memory includes:

判断采用独立缓冲方式进行缓冲或者采用非独立缓冲方式进行缓冲;Determine whether to use independent buffering for buffering or non-independent buffering for buffering;

若判断出采用所述独立缓冲方式进行缓冲,则将每个压缩音视频帧写入对应的帧缓冲区中;If it is determined that the independent buffering mode is used for buffering, each compressed audio and video frame is written into the corresponding frame buffer;

若判断出采用非独立缓冲方式进行缓冲,则将全部的所述压缩音视频帧写入一个帧缓冲区中。If it is determined that the non-independent buffering mode is used for buffering, all the compressed audio and video frames are written into a frame buffer.

可选的,所述对所述至少一个起始码在所述多个环形缓冲的位置进行识别之前,还包括:Optionally, before the identifying the positions of the at least one start code in the plurality of ring buffers, the method further includes:

根据码流的编码规范设置至少一个起始码。Set at least one start code according to the encoding specification of the code stream.

可选的,获取所述环形缓冲中的所述起始码的个数;Optionally, obtain the number of the start codes in the ring buffer;

在所述起始码缓冲区中读取与所述起始码个数对应数量的所述起始码在环形缓冲中的物理地址;Reading the physical addresses of the start codes in the ring buffer corresponding to the number of the start codes in the start code buffer;

根据所述物理地址在环形缓冲中查找出所述物理地址对应的起始码;Find out the start code corresponding to the physical address in the ring buffer according to the physical address;

在所述PES数据中,从所述物理地址对应的起始码开始检测出符合帧边界编码规则的部分,并将符合帧边界编码规则的部分确定为帧边界;In the PES data, the start code corresponding to the physical address starts to detect the part that meets the frame boundary coding rule, and the part that meets the frame boundary coding rule is determined as the frame boundary;

根据识别出的帧边界进行组帧,生成所述压缩音视频帧。Framing is performed according to the identified frame boundaries to generate the compressed audio and video frames.

另一方面,本发明实施例提供了一种音视频码流的处理装置,包括:On the other hand, an embodiment of the present invention provides an apparatus for processing audio and video streams, including:

生成模块,用于根据接收到的信号,生成传输流;The generation module is used to generate the transport stream according to the received signal;

过滤模块,用于从传输流中过滤出音视频码流,所述音视频码流包括PES数据;A filtering module, configured to filter out an audio and video code stream from the transport stream, where the audio and video code stream includes PES data;

第一写入模块,用于将所述PES数据写入内存的多个环形缓冲中,所述PES数据包括至少一个起始码;a first writing module, configured to write the PES data into multiple ring buffers of the memory, the PES data including at least one start code;

第一识别模块,用于对所述至少一个起始码在所述多个环形缓冲的位置进行识别,得到所述位置对应的物理地址;a first identification module, configured to identify the position of the at least one start code in the plurality of ring buffers to obtain a physical address corresponding to the position;

第一记录模块,用于将所述物理地址记录到所述内存的起始码缓冲区中;a first recording module, for recording the physical address in the start code buffer of the memory;

解析模块,用于响应于生成的中断通知信号,根据所述物理地址对所述PES数据进行解析生成压缩音视频帧;A parsing module, configured to parse the PES data according to the physical address to generate a compressed audio and video frame in response to the generated interrupt notification signal;

第二写入模块,用于将所述压缩音视频帧写入到所述内存中的至少一个帧缓冲区中。The second writing module is configured to write the compressed audio and video frames into at least one frame buffer in the memory.

另一方面,本发明实施例提供了一种存储介质,其特征在于,所述存储介质包括存储的程序,其中,在所述程序运行时控制所存储介质所在设备执行上述的音视频码流的处理方法。On the other hand, an embodiment of the present invention provides a storage medium, characterized in that the storage medium includes a stored program, wherein when the program is run, a device where the stored medium is located is controlled to execute the above-mentioned audio and video code streams. Approach.

另一方面,本发明实施例提供了一种第一电子设备,其特征在于,包括存储器、处理器以及存储在所述存储器中并可在所述处理器上运行的计算机程序,所述处理器执行所述计算机程序时实现如上述的音视频码流的处理方法。On the other hand, an embodiment of the present invention provides a first electronic device, which is characterized by comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, the processor When the computer program is executed, the above-mentioned audio and video code stream processing method is realized.

本发明实施例提供的技术方案中,根据接收到的信号,生成传输流,从传输流中过滤出音视频码流,所述音视频码流包括打包的基本码流PES数据,将所述PES数据写入内存的多个环形缓冲中,所述PES数据包括至少一个起始码,对所述至少一个起始码在所述多个环形缓冲的位置进行识别,得到所述位置对应的物理地址,将所述物理地址记录到所述内存的起始码缓冲区中,响应于生成的中断通知信号,根据所述物理地址对所述PES数据进行解析生成压缩音视频帧,并将所述压缩音视频帧写入到所述内存中的至少一个帧缓冲区中,减少了由于拷贝压缩音视频帧导致的系统性能下降,提高了组帧速度,减少了延时较长引起的丢帧卡顿。In the technical solution provided by the embodiment of the present invention, a transport stream is generated according to the received signal, and an audio and video code stream is filtered out from the transport stream. The data is written into multiple ring buffers in the memory, the PES data includes at least one start code, the position of the at least one start code in the multiple ring buffers is identified, and the physical address corresponding to the position is obtained , record the physical address in the start code buffer of the memory, and in response to the generated interrupt notification signal, parse the PES data according to the physical address to generate a compressed audio and video frame, and compress the compressed audio and video frames. The audio and video frames are written into at least one frame buffer in the memory, which reduces the system performance degradation caused by copying and compressing the audio and video frames, improves the frame rate, and reduces the frame loss caused by the long delay. .

【附图说明】【Description of drawings】

为了更清楚地说明本发明实施例的技术方案,下面将对实施例中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动性的前提下,还可以根据这些附图获得其它的附图。In order to illustrate the technical solutions of the embodiments of the present invention more clearly, the following briefly introduces the accompanying drawings used in the embodiments. Obviously, the drawings in the following description are only some embodiments of the present invention. For those of ordinary skill in the art, other drawings can also be obtained from these drawings without any creative effort.

图1为本发明实施例提供的一种音视频码流的处理方法的流程图;1 is a flowchart of a method for processing audio and video code streams according to an embodiment of the present invention;

图2为本发明实施例提供的一种数据传输的示意图;2 is a schematic diagram of a data transmission provided by an embodiment of the present invention;

图3为本发明实施例提供的一种内部标识的示意图;3 is a schematic diagram of an internal identification provided by an embodiment of the present invention;

图4为本发明实施例提供的一种缓冲区搜索原理的示意图;4 is a schematic diagram of a buffer search principle according to an embodiment of the present invention;

图5为本发明实施例提供的一种音视频码流的处理装置的示意图;5 is a schematic diagram of an apparatus for processing audio and video code streams according to an embodiment of the present invention;

图6为本发明实施例提供的一种电子设备的示意图。FIG. 6 is a schematic diagram of an electronic device according to an embodiment of the present invention.

【具体实施方式】【Detailed ways】

为了更好的理解本发明的技术方案,下面结合附图对本发明实施例进行详细描述。In order to better understand the technical solutions of the present invention, the embodiments of the present invention are described in detail below with reference to the accompanying drawings.

应当明确,所描述的实施例仅仅是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其它实施例,都属于本发明保护的范围。It should be understood that the described embodiments are only some, but not all, embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention.

在本发明实施例中使用的术语是仅仅出于描述特定实施例的目的,而非旨在限制本发明。在本发明实施例和所附权利要求书中所使用的单数形式的“一种”、“所述”和“该”也旨在包括多数形式,除非上下文清楚地表示其他含义。The terms used in the embodiments of the present invention are only for the purpose of describing specific embodiments, and are not intended to limit the present invention. As used in the embodiments of the present invention and the appended claims, the singular forms "a," "the," and "the" are intended to include the plural forms as well, unless the context clearly dictates otherwise.

应当理解,本文中使用的术语“和/或”仅仅是一种描述关联对象的关联关系,表示可以存在三种关系,例如,A和/或B,可以表示:单独存在A,同时存在A和B,单独存在B这三种情况。另外,本文中字符“/”,一般表示前后关联对象是一种“或”的关系。It should be understood that the term "and/or" used in this document is only an association relationship to describe the associated objects, indicating that there may be three kinds of relationships, for example, A and/or B, which may indicate that A exists alone, and A and B exist at the same time. B, there are three cases of B alone. In addition, the character "/" in this document generally indicates that the related objects are an "or" relationship.

应当理解,尽管在本发明实施例中可能采用术语第一、第二、第三等来描述数目等,但这些数目不应限于这些术语。这些术语仅用来将数目彼此区分开。例如,在不脱离本发明实施例范围的情况下,第一数目也可以被称为第二数目,类似地,第二数目也可以被称为第一数目。It should be understood that although the terms first, second, third, etc. may be used in the embodiments of the present invention to describe numbers, etc., these numbers should not be limited to these terms. These terms are only used to distinguish numbers from one another. For example, the first number may also be referred to as the second number, and similarly, the second number may also be referred to as the first number without departing from the scope of the embodiments of the present invention.

取决于语境,如在此所使用的词语“如果”可以被解释成为“在……时”或“当……时”或“响应于确定”或“响应于检测”。类似地,取决于语境,短语“如果确定”或“如果检测(陈述的条件或事件)”可以被解释成为“当确定时”或“响应于确定”或“当检测(陈述的条件或事件)时”或“响应于检测(陈述的条件或事件)”。Depending on the context, the word "if" as used herein can be interpreted as "at" or "when" or "in response to determining" or "in response to detecting." Similarly, the phrases "if determined" or "if detected (the stated condition or event)" can be interpreted as "when determined" or "in response to determining" or "when detected (the stated condition or event)," depending on the context )" or "in response to detection (a stated condition or event)".

图1为本发明实施例提供的一种音视频码流的处理方法的流程图,如图1所示,所述方法包括:FIG. 1 is a flowchart of a method for processing audio and video code streams according to an embodiment of the present invention. As shown in FIG. 1 , the method includes:

步骤101、根据接收到的信号,生成传输流。Step 101: Generate a transport stream according to the received signal.

本发明实施例中的各步骤可以由电子设备执行,电子设备包括但不限于智能电视、手机、平板电脑、个人计算机等,例如,电子设备还可以包括能够收看移动电视节目的其它电子设备。The steps in the embodiments of the present invention may be performed by electronic devices, including but not limited to smart TVs, mobile phones, tablet computers, personal computers, etc. For example, the electronic devices may also include other electronic devices capable of watching mobile TV programs.

本发明实施例中,该信号可以为射频信号。In this embodiment of the present invention, the signal may be a radio frequency signal.

本发明实施例中,电子设备包括芯片,芯片内集成Demux硬件,例如,芯片为电视芯片。In this embodiment of the present invention, the electronic device includes a chip, and Demux hardware is integrated in the chip, for example, the chip is a TV chip.

本发明实施例中,电子设备包括调谐器、解调器、寄存器和Demux硬件。In this embodiment of the present invention, the electronic device includes a tuner, a demodulator, a register, and Demux hardware.

本发明实施例中,可通过调谐器和解调器对接收到的信号进行处理,生成传输流。In this embodiment of the present invention, a tuner and a demodulator may be used to process the received signal to generate a transport stream.

步骤102、从传输流中过滤出音视频码流,音视频码流包括PES数据。Step 102: Filter out an audio and video code stream from the transport stream, where the audio and video code stream includes PES data.

本发明实施例中,步骤102至步骤105均可由Demux硬件执行。本发明实施例中,通过设置的PID对所述传输流进行过滤,生成所述音视频码流,例如,该音视频码流为数字电视(Digital Television,DTV)音视频码流。In this embodiment of the present invention, steps 102 to 105 can be performed by Demux hardware. In the embodiment of the present invention, the transport stream is filtered by the set PID to generate the audio and video code stream, for example, the audio and video code stream is a digital television (Digital Television, DTV) audio and video code stream.

本发明实施例中,传输流可包括音视频码流、字幕、业务信息等各种格式的码流数据。Demux硬件可分离音视频码流、字幕、业务信息表等各种格式的码流数据。In this embodiment of the present invention, the transport stream may include code stream data in various formats, such as audio and video code streams, subtitles, and service information. Demux hardware can separate code stream data in various formats, such as audio and video code streams, subtitles, and service information tables.

本发明实施例中,生成传输流后根据设置的PID对传输流进行过滤,过滤出PID对应的码流。PID是一个数值,同一段传输流中的每一种数据类型对应唯一的PID值。因此,通过设置的PID,可以从传输流中过滤出PID对应的音视频码流。In the embodiment of the present invention, after the transport stream is generated, the transport stream is filtered according to the set PID, and the code stream corresponding to the PID is filtered out. PID is a numerical value, and each data type in the same transport stream corresponds to a unique PID value. Therefore, through the set PID, the audio and video stream corresponding to the PID can be filtered out from the transport stream.

本发明实施例中,生成传输流后根据通过驱动软件设置的PID对传输流进行过滤,过滤出PID对应的码流。In the embodiment of the present invention, after the transport stream is generated, the transport stream is filtered according to the PID set by the driver software, and the code stream corresponding to the PID is filtered out.

本发明实施例中,传输流是指将具有共同时间基准或独立时间基准的一个或多个PES数据组合而成的单一数据流。将基本码流分割成多个子基本码流,将每个子基本码流加上对应的头进行打包形成PES数据,将PES数据作为传输流的有效负载由传输流分组携带。将子基本码流打包形成多个PES数据时,每个PES数据的数据量可以不同,也可以相同。In this embodiment of the present invention, a transport stream refers to a single data stream formed by combining one or more PES data having a common time reference or an independent time reference. The elementary code stream is divided into multiple sub-elementary code streams, and each sub-elementary code stream is packaged with the corresponding header to form PES data, and the PES data is used as the payload of the transport stream to be carried by the transport stream packets. When the sub-elementary stream is packaged to form multiple PES data, the data amount of each PES data may be different or the same.

步骤103、将PES数据写入内存的多个环形缓冲中,PES数据包括至少一个起始码。Step 103: Write PES data into multiple ring buffers in the memory, where the PES data includes at least one start code.

本发明实施例中,可以动态分配内存,将分配的内存组织为环形链表,环形链表中包括环形缓冲的物理地址。根据环形链表中环形缓冲的物理地址获取物理地址对应的内存,将PES数据写入物理地址对应的环形缓冲中。In the embodiment of the present invention, the memory can be dynamically allocated, and the allocated memory is organized into a circular linked list, and the circular linked list includes the physical address of the ring buffer. The memory corresponding to the physical address is obtained according to the physical address of the ring buffer in the ring linked list, and the PES data is written into the ring buffer corresponding to the physical address.

本发明实施例中,通过驱动软件可以动态分配内存,将分配的内存组织为环形链表,环形链表中包括环形缓冲的物理地址。根据链表内存放的物理地址向物理地址对应的环形缓冲中写入PES数据。In the embodiment of the present invention, the driver software can dynamically allocate memory, and organize the allocated memory into a circular linked list, and the circular linked list includes the physical address of the ring buffer. Write PES data into the ring buffer corresponding to the physical address according to the physical address stored in the linked list.

图2为本发明实施例提供的一种数据传输的示意图,如图2所示,内存中包含多个环形缓冲,每个环形缓冲的大小相同,将多个PES数据依次写入多个环形缓冲(dscr)中,一个PES数据可以占据多个环形缓冲,若一个PES数据已经全部写入环形缓冲中,但并未将最后写入的环形缓冲填满,在写入新的PES数据时,将新的PES数据写入一个新的环形缓冲中。例如,将两个PES包写入环形缓冲中,先将第一PES数据(PES data1)写入第一环形缓冲中,将第一环形缓冲写满后,将第一PES剩余数据写入后面的环形缓冲中,直到将第一PES数据写完。将第一PES数据全部写入环形缓冲后,第一环形缓冲和第二环形缓冲被填满,第三环形缓冲仅被填入一部分。当写入第二PES数据时,将第二PES数据(PES data2)从第四环形缓冲开始写入环形缓冲,若第四环形缓冲写满,则继续写入后面的环形缓冲,直至第二PES数据全部写入环形缓冲。FIG. 2 is a schematic diagram of a data transmission provided by an embodiment of the present invention. As shown in FIG. 2 , the memory includes multiple ring buffers, and each ring buffer has the same size, and multiple PES data are sequentially written into the multiple ring buffers In (dscr), one PES data can occupy multiple ring buffers. If one PES data has been written into the ring buffer, but the last written ring buffer has not been filled, when new PES data is written, the New PES data is written to a new ring buffer. For example, to write two PES packets into the ring buffer, first write the first PES data (PES data1) into the first ring buffer, after the first ring buffer is full, write the remaining data of the first PES into the following Ring buffer until the first PES data is written. After all the first PES data is written into the ring buffer, the first ring buffer and the second ring buffer are filled, and the third ring buffer is only partially filled. When writing the second PES data, write the second PES data (PES data2) into the ring buffer starting from the fourth ring buffer. If the fourth ring buffer is full, continue to write the following ring buffers until the second PES All data is written to the ring buffer.

步骤104、对至少一个起始码在多个环形缓冲的位置进行识别,得到位置对应的物理地址。Step 104: Identify the positions of at least one start code in multiple ring buffers to obtain a physical address corresponding to the position.

本发明实施例中,所述对所述至少一个起始码在所述多个环形缓冲的位置进行识别之前,还包括:根据码流的编码规范设置至少一个起始码。In the embodiment of the present invention, before the identifying the positions of the at least one start code in the plurality of ring buffers, the method further includes: setting at least one start code according to a coding specification of the code stream.

本发明实施例中,根据不同码流的编码规范设置起始码,例如,对于H264码流,可以设置起始码为0x00000148等。In this embodiment of the present invention, the start code is set according to the coding specifications of different code streams. For example, for the H264 code stream, the start code may be set to 0x00000148 and the like.

本发明实施例中,通过驱动软件根据不同码流的编码规范设置起始码。In the embodiment of the present invention, the start code is set according to the coding specifications of different code streams through the driver software.

本发明实施例中,起始码可以设置为一个,也可以设置多个,起始码本身也是PES编码中的一部分。同一起始码在一个环形缓冲中可以识别出多个。例如,将起始码设置为0x00000148,若在一个环形缓冲中识别出3个0x00000148编码,识别出的3个0x00000148编码均确认为起始码。根据识别到的起始码,获取每个起始码在这个环形缓冲中对应的物理地址。In this embodiment of the present invention, the start code may be set to one or multiple, and the start code itself is also a part of the PES encoding. The same start code can be recognized more than one in a ring buffer. For example, if the start code is set to 0x00000148, if three codes of 0x00000148 are identified in a ring buffer, the identified three codes of 0x00000148 are all confirmed as the start code. According to the identified start codes, the physical address corresponding to each start code in the ring buffer is obtained.

本发明实施例中,寄存器内部包括设置的起始码,Demux硬件获取寄存器中的起始码。对起始码的位置进行识别,识别出起始码在每个环形缓冲中的位置,获取位置对应的物理地址,每个物理地址包含4个字节。In this embodiment of the present invention, the register includes a set start code, and the Demux hardware obtains the start code in the register. The position of the start code is identified, the position of the start code in each ring buffer is identified, and the physical address corresponding to the position is obtained, and each physical address contains 4 bytes.

步骤105、将物理地址记录到内存的起始码缓冲区中。Step 105: Record the physical address in the start code buffer of the memory.

本发明实施例中,步骤105之前还包括:分配一个指定大小的缓冲区,将所述指定大小的缓冲区作为所述起始码缓冲区。In this embodiment of the present invention, before step 105, the method further includes: allocating a buffer of a specified size, and using the buffer of the specified size as the start code buffer.

本发明实施例中,起始码缓冲区用于存放不同起始码在环形缓冲中的地址。动态分配一个指定大小的缓冲区,并将该指定大小的缓冲区作为起始码缓冲区。例如,指定大小为1k。调用起始码缓冲区,将每个起始码在环形缓冲中对应的物理地址依次写入起始码缓冲区。In this embodiment of the present invention, the start code buffer is used to store addresses of different start codes in the ring buffer. Dynamically allocate a buffer of the specified size and use the buffer of the specified size as the start code buffer. For example, specify a size of 1k. The start code buffer is called, and the physical address corresponding to each start code in the ring buffer is sequentially written into the start code buffer.

本发明实施例中,通过驱动软件动态分配一个指定大小的缓冲区,并将该指定大小的缓冲区作为起始码缓冲区。In the embodiment of the present invention, a buffer of a specified size is dynamically allocated by the driver software, and the buffer of the specified size is used as the start code buffer.

步骤106、响应于生成的中断通知信号,根据物理地址对PES数据进行解析生成压缩音视频帧,并将压缩音视频帧写入到内存中的至少一个帧缓冲区中。Step 106: In response to the generated interrupt notification signal, analyze the PES data according to the physical address to generate a compressed audio and video frame, and write the compressed audio and video frame into at least one frame buffer in the memory.

本发明实施例中,步骤106之前包括:对所述至少一个起始码在所述多个环形缓冲的个数进行识别,生成每个所述环形缓冲对应的所述起始码的个数,将所述起始码的个数记录到对应的所述环形缓冲中。In this embodiment of the present invention, before step 106, the steps include: identifying the number of the at least one start code in the plurality of ring buffers, and generating the number of the start codes corresponding to each of the ring buffers, Record the number of the start codes into the corresponding ring buffer.

图3为本发明实施例提供的一种内部标识的示意图,如图3所示,根据驱动软件设置的起始码识别出每个环形缓冲中的起始码的个数,在每个环形缓冲内部生成一个内部标识scode_cnt,通过内部标识scode_cnt记录每个环形缓冲中存在的起始码个数。例如,若一个环形缓冲中包括内部标识scode_cnt:2,则表示该环形缓冲中包含2个起始码。FIG. 3 is a schematic diagram of an internal identification provided by an embodiment of the present invention. As shown in FIG. 3 , the number of start codes in each ring buffer is identified according to the start code set by the driver software. An internal identifier scode_cnt is generated internally, and the number of start codes existing in each ring buffer is recorded through the internal identifier scode_cnt. For example, if a ring buffer includes the internal identifier scode_cnt: 2, it means that the ring buffer includes 2 start codes.

本发明实施例中,将所有PES数据写入环形缓冲后,使Demux硬件发生中断,通过中断通知驱动软件中的中断服务程序(Interrupt Service Routines,ISR)解析环形缓冲中的PES数据。In the embodiment of the present invention, after all PES data are written into the ring buffer, the Demux hardware is interrupted, and the interrupt service routine (Interrupt Service Routines, ISR) in the driver software is notified to parse the PES data in the ring buffer.

本发明实施例中,所述对所述PES数据进行解析生成压缩音视频帧,包括:In the embodiment of the present invention, the generating of compressed audio and video frames by parsing the PES data includes:

步骤1061、获取所述环形缓冲中的所述起始码的个数。Step 1061: Acquire the number of the start codes in the ring buffer.

本发明实施例中,对PES数据进行解析生成压缩音视频帧包括对多个环形缓冲中的数据依次进行解析,获取当前正在解析的环形缓冲中的内部标识记录的起始码个数。例如,第一个环形缓冲内部标识为scode_cnt:2,在解析第一个环形缓冲中的数据时,根据内部标识scode_cnt:2获取当前环形缓冲中的起始码个数为2个。In the embodiment of the present invention, parsing the PES data to generate the compressed audio and video frames includes sequentially parsing the data in multiple ring buffers, and obtaining the number of start codes of the internal identification records in the currently parsing ring buffer. For example, the internal identifier of the first ring buffer is scode_cnt: 2. When parsing the data in the first ring buffer, the number of start codes in the current ring buffer is obtained according to the internal identifier scode_cnt: 2.

步骤1062、在所述起始码缓冲区中读取与所述起始码个数对应数量的所述起始码在环形缓冲中的物理地址。Step 1062: Read the physical addresses of the start codes in the ring buffer in the number corresponding to the number of the start codes in the start code buffer.

图4为本发明实施例提供的一种缓冲区搜索原理的示意图,如图4所示,根据获取的环形缓冲中的起始码个数,确定在起始码缓冲区中获取的物理地址数量,在起始码缓冲区中找到与当前正在解析的环形缓冲中与起始码个数对应数量的物理地址。当解析新的环形缓冲中的数据时,从起始码缓冲区中上一次获取物理地址截止的位置开始获取当前环形缓冲中起始码个数对应数量的物理地址。例如,第一个环形缓冲内部标识scode_cnt:2,第二个环形缓冲内部标识scode_cnt:3,当解析第一个环形缓冲中的PES数据时,根据内部标识scode_cnt:2,在起始码缓冲区中获取第一物理地址(Address 1)和第二物理地址(Address 2),将第一物理地址和第二物理地址作为第一环形缓冲中的两个起始码对应的物理地址,当解析第二环形缓冲中的PES数据时,根据内部标识scode_cnt:3,在起始码缓冲区中获取第三物理地址(Address 3)、第四物理地址(Address 4)和第五物理地址(Address5),将第三物理地址、第四物理地址和第五物理地址作为第二环形缓冲中的三个起始码对应的物理地址。FIG. 4 is a schematic diagram of a buffer search principle provided by an embodiment of the present invention. As shown in FIG. 4 , the number of physical addresses acquired in the start code buffer is determined according to the acquired number of start codes in the ring buffer , find in the start code buffer the number of physical addresses corresponding to the number of start codes in the currently parsed ring buffer. When parsing the data in the new ring buffer, the number of physical addresses corresponding to the number of start codes in the current ring buffer is obtained from the position where the last physical address obtained in the start code buffer ends. For example, the internal identification of the first ring buffer is scode_cnt: 2, and the internal identification of the second ring buffer is scode_cnt: 3. When parsing the PES data in the first ring buffer, according to the internal identification scode_cnt: 2, in the start code buffer Obtain the first physical address (Address 1) and the second physical address (Address 2) in the When there is PES data in the second ring buffer, the third physical address (Address 3), the fourth physical address (Address 4) and the fifth physical address (Address5) are obtained in the start code buffer according to the internal identifier scode_cnt: 3, The third physical address, the fourth physical address and the fifth physical address are used as the physical addresses corresponding to the three start codes in the second ring buffer.

步骤1063、根据所述物理地址在环形缓冲中查找出所述物理地址对应的起始码。Step 1063: Find the start code corresponding to the physical address in the ring buffer according to the physical address.

步骤1064、在所述PES数据中,从所述物理地址对应的起始码开始检测出符合帧边界编码规则的部分,并将符合帧边界编码规则的部分确定为帧边界。Step 1064: In the PES data, start from the start code corresponding to the physical address to detect the part conforming to the frame boundary coding rule, and determine the part conforming to the frame boundary coding rule as the frame boundary.

本发明实施例中,对环形缓冲中起始码的位置进行查找,根据位置找到的起始码,并检测起始码后面的数据。由于编码方式不同,编码的规则也不同,根据当前所用编码的编码规则,检测出PES数据中符合帧边界规则的部分数据,将符合帧边界规则的部分数据确定为帧边界。In the embodiment of the present invention, the position of the start code in the ring buffer is searched, and the data following the start code is detected according to the start code found in the position. Due to the different encoding methods, the encoding rules are also different. According to the encoding rules currently used, the part of the data that conforms to the frame boundary rules in the PES data is detected, and the part of the data that conforms to the frame boundary rules is determined as the frame boundary.

步骤1065、根据识别出的帧边界进行组帧,生成所述压缩音视频帧。Step 1065: Perform framing according to the identified frame boundaries to generate the compressed audio and video frames.

本发明实施例中,通过起始码缓冲区中的物理地址,找到环形缓冲中的起始码,根据起始码开始识别帧边界,可以快速识别出帧边界,因此,无需逐字解析整个码流就能完成组帧操作。In the embodiment of the present invention, the start code in the ring buffer is found through the physical address in the start code buffer, and the frame boundary is identified according to the start code, so that the frame boundary can be quickly identified, so it is not necessary to parse the entire code word by word. The stream can complete the framing operation.

本发明实施例中,所述将所述压缩音视频帧写入到内存中的至少一个帧缓冲区中,包括:In the embodiment of the present invention, the writing of the compressed audio and video frames into at least one frame buffer in the memory includes:

步骤1066、判断采用独立缓冲方式进行缓冲或者采用非独立缓冲方式进行缓冲。若判断出采用独立缓冲方式进行缓冲,执行步骤1067;若判断出采用非独立缓冲方式进行缓冲,执行步骤1068。Step 1066: Determine whether to use an independent buffering mode for buffering or a non-independent buffering mode to perform buffering. If it is determined that the independent buffering mode is used for buffering, step 1067 is executed; if it is determined that the non-independent buffering mode is used for buffering, step 1068 is executed.

本发明实施例中,将帧缓冲区在上层用户空间进行分配,并将帧缓冲区的句柄传递给驱动软件,对帧缓冲区进行映射操作以将帧缓冲区的地址转换为内核虚拟地址,使上层用户空间和驱动软件能够共享帧缓冲区。将PES数据解析后的压缩音视频帧直接写入到帧缓冲区,由于上层用户空间和驱动软件能够共享帧缓冲区中的压缩音视频帧,避免了内核和用户空间之间的拷贝操作。In the embodiment of the present invention, the frame buffer is allocated in the upper-layer user space, the handle of the frame buffer is passed to the driver software, and the frame buffer is mapped to convert the address of the frame buffer into the kernel virtual address, so that the Upper user space and driver software can share the frame buffer. The compressed audio and video frames parsed by PES data are directly written into the frame buffer. Since the upper user space and the driver software can share the compressed audio and video frames in the frame buffer, the copy operation between the kernel and the user space is avoided.

本发明实施例中,通过驱动软件将帧缓冲区的地址转换为内核虚拟地址,使上层用户空间和驱动软件能够共享帧缓冲区。In the embodiment of the present invention, the address of the frame buffer is converted into a kernel virtual address by the driver software, so that the upper-layer user space and the driver software can share the frame buffer.

本发明实施例中,可预先设置需要采用的缓冲方式,若检测出预先设置的缓冲方式为独立缓冲方式,则判断出采用独立缓冲方式进行缓冲;若检测出预先设置的缓冲方式为非独立缓冲方式,则判断出采用非独立缓冲方式进行缓冲。In the embodiment of the present invention, the buffering mode to be used may be preset. If it is detected that the preset buffering mode is an independent buffering mode, it is determined that the independent buffering mode is used for buffering; if it is detected that the preset buffering mode is a non-independent buffering mode mode, it is determined to use the non-independent buffering mode for buffering.

步骤1067、将每个压缩音视频帧写入对应的帧缓冲区中。Step 1067: Write each compressed audio and video frame into the corresponding frame buffer.

本发明实施例中,采用独立缓冲方式进行缓冲时,会产生多个帧缓冲区,向每个帧缓冲区中写入一个压缩音视频帧,即一个帧缓冲区只包括一个压缩音视频帧。In the embodiment of the present invention, when independent buffering is used for buffering, multiple frame buffers are generated, and one compressed audio and video frame is written into each frame buffer, that is, one frame buffer only includes one compressed audio and video frame.

本发明实施例中,采用独立缓冲方式进行缓冲时,会产生多个帧缓冲区,通过驱动软件向每个帧缓冲区中写入一个压缩音视频帧。In the embodiment of the present invention, when buffering is performed in an independent buffering manner, multiple frame buffers are generated, and a compressed audio and video frame is written into each frame buffer through driving software.

步骤1068、将全部的所述压缩音视频帧写入一个帧缓冲区中。Step 1068: Write all the compressed audio and video frames into a frame buffer.

本发明实施例中,采用非独立缓冲方式进行缓冲时,只产生一个帧缓冲区,将全部的压缩音视频帧写入到这一个帧缓冲区中,根据写入的压缩音视频帧写入的位置记录一个对应的偏移位置,每写入一个压缩音视频帧记录一次偏移位置,将偏移位置确定为下一个压缩音视频帧写入的位置。In the embodiment of the present invention, when buffering is performed in a non-independent buffering manner, only one frame buffer is generated, and all the compressed audio and video frames are written into this frame buffer, and the compressed audio and video frames are written according to the written compressed audio and video frames. The position records a corresponding offset position, and the offset position is recorded every time a compressed audio and video frame is written, and the offset position is determined as the position where the next compressed audio and video frame is written.

本发明实施例中,采用非独立缓冲方式进行缓冲时,只产生一个帧缓冲区,通过驱动软件将全部的压缩音视频帧写入到这一个帧缓冲区中。In the embodiment of the present invention, when buffering is performed in a non-independent buffering manner, only one frame buffer is generated, and all compressed audio and video frames are written into this one frame buffer through the driver software.

本发明实施例提供的技术方案中,根据接收到的信号,生成传输流,从传输流中过滤出音视频码流,所述音视频码流包括打包的基本码流PES数据,将所述PES数据写入内存的多个环形缓冲中,所述PES数据包括至少一个起始码,对所述至少一个起始码在所述多个环形缓冲的位置进行识别,得到所述位置对应的物理地址,将所述物理地址记录到所述内存的起始码缓冲区中,响应于生成的中断通知信号,根据所述物理地址对所述PES数据进行解析生成压缩音视频帧,并将所述压缩音视频帧写入到所述内存中的至少一个帧缓冲区中,减少了由于拷贝压缩音视频帧导致的系统性能下降,提高了组帧速度,减少了延时较长引起的丢帧卡顿。In the technical solution provided by the embodiment of the present invention, a transport stream is generated according to the received signal, and an audio and video code stream is filtered out from the transport stream. The data is written into multiple ring buffers in the memory, the PES data includes at least one start code, the position of the at least one start code in the multiple ring buffers is identified, and the physical address corresponding to the position is obtained , record the physical address in the start code buffer of the memory, and in response to the generated interrupt notification signal, parse the PES data according to the physical address to generate a compressed audio and video frame, and compress the compressed audio and video frames. The audio and video frames are written into at least one frame buffer in the memory, which reduces the system performance degradation caused by copying and compressing the audio and video frames, improves the frame rate, and reduces the frame loss caused by the long delay. .

图5为本发明实施例提供的一种音视频码流的处理装置的结构示意图,如图5所示,该装置包括:生成模块1、过滤模块2、第一写入模块3、第一识别模块4、第一记录模块5、解析模块6和第二写入模块7。FIG. 5 is a schematic structural diagram of an apparatus for processing audio and video code streams according to an embodiment of the present invention. As shown in FIG. 5 , the apparatus includes: a generating module 1, a filtering module 2, a first writing module 3, a first identifying module Module 4 , first recording module 5 , parsing module 6 and second writing module 7 .

本发明实施例中,生成模块1用于根据接收到的信号,生成传输流。过滤模块2用于从传输流中过滤出音视频码流,所述音视频码流包括PES数据。第一写入模块3用于将所述PES数据写入内存的多个环形缓冲中,所述PES数据包括至少一个起始码。第一识别模块4用于对所述至少一个起始码在所述多个环形缓冲的位置进行识别,得到所述位置对应的物理地址。第一记录模块5用于将所述物理地址记录到所述内存的起始码缓冲区中。解析模块6用于响应于生成的中断通知信号,根据所述物理地址对所述PES数据进行解析生成压缩音视频帧。第二写入模块7用于将所述压缩音视频帧写入到所述内存中的至少一个帧缓冲区中。In this embodiment of the present invention, the generating module 1 is configured to generate a transport stream according to the received signal. The filtering module 2 is configured to filter out an audio and video code stream from the transport stream, where the audio and video code stream includes PES data. The first writing module 3 is configured to write the PES data into multiple ring buffers in the memory, where the PES data includes at least one start code. The first identification module 4 is configured to identify the position of the at least one start code in the plurality of ring buffers to obtain a physical address corresponding to the position. The first recording module 5 is used for recording the physical address into the start code buffer of the memory. The parsing module 6 is configured to parse the PES data according to the physical address in response to the generated interrupt notification signal to generate a compressed audio and video frame. The second writing module 7 is configured to write the compressed audio and video frames into at least one frame buffer in the memory.

本发明实施例中,所述过滤模块2具体用于通过设置的PID对所述传输流进行过滤,生成所述音视频码流。In this embodiment of the present invention, the filtering module 2 is specifically configured to filter the transport stream by using the set PID to generate the audio and video stream.

本发明实施例中,该装置还包括:第二识别模块8和第二记录模块9。第二识别模块8用于对所述至少一个起始码在所述多个环形缓冲的个数进行识别,生成每个所述环形缓冲对应的所述起始码的个数。第二记录模块9用于将所述起始码的个数记录到对应的所述环形缓冲中。In this embodiment of the present invention, the device further includes: a second identification module 8 and a second recording module 9 . The second identification module 8 is configured to identify the number of the at least one start code in the plurality of ring buffers, and generate the number of the start code corresponding to each of the ring buffers. The second recording module 9 is configured to record the number of the start codes into the corresponding ring buffer.

本发明实施例中,该装置还包括:分配模块10。分配模块10用于分配一个指定大小的缓冲区,将所述指定大小的缓冲区作为所述起始码缓冲区。In this embodiment of the present invention, the apparatus further includes: a distribution module 10 . The allocation module 10 is configured to allocate a buffer of a specified size, and use the buffer of the specified size as the start code buffer.

本发明实施例中,所述第二写入模块7包括判断子模块71和写入子模块72。判断子模块71用于判断采用独立缓冲方式进行缓冲或者采用非独立缓冲方式进行缓冲。写入子模块72用于若判断子模块71判断出采用所述独立缓冲方式进行缓冲,则将每个压缩音视频帧写入对应的帧缓冲区中;若判断子模块71判断出采用非独立缓冲方式进行缓冲,则将全部的所述压缩音视频帧写入一个帧缓冲区中。In this embodiment of the present invention, the second writing module 7 includes a judging submodule 71 and a writing submodule 72 . The judging sub-module 71 is used for judging whether to use an independent buffering mode for buffering or a non-independent buffering mode for buffering. The writing submodule 72 is used to write each compressed audio and video frame into the corresponding frame buffer if the judging submodule 71 judges that the independent buffering mode is used for buffering; if the judging submodule 71 judges that the non-independent If buffering is used for buffering, all the compressed audio and video frames are written into a frame buffer.

本发明实施例中,该装置还包括设置模块11。设置模块11用于根据码流的编码规范设置至少一个起始码。In this embodiment of the present invention, the device further includes a setting module 11 . The setting module 11 is configured to set at least one start code according to the encoding specification of the code stream.

本发明实施例中,解析模块6包括获取子模块61、读取子模块62、查找子模块63、检测子模块64和组帧子模块65。获取子模块61用于获取所述环形缓冲中的所述起始码的个数。读取子模块62用于在所述起始码缓冲区中读取与所述起始码个数对应数量的所述起始码在环形缓冲中的物理地址。查找子模块63用于根据所述物理地址在环形缓冲中查找出所述物理地址对应的起始码。检测子模块64用于在所述PES数据中,从所述物理地址对应的起始码开始检测出符合帧边界编码规则的部分,并将符合帧边界编码规则的部分确定为帧边界。组帧子模块65用于根据识别出的帧边界进行组帧,生成所述压缩音视频帧。In the embodiment of the present invention, the parsing module 6 includes an acquisition sub-module 61 , a reading sub-module 62 , a search sub-module 63 , a detection sub-module 64 and a framing sub-module 65 . The obtaining sub-module 61 is configured to obtain the number of the start codes in the ring buffer. The reading submodule 62 is configured to read, from the start code buffer, the physical addresses of the start codes in the ring buffer corresponding to the number of the start codes. The search sub-module 63 is configured to search for the start code corresponding to the physical address in the ring buffer according to the physical address. The detection submodule 64 is configured to detect the part conforming to the frame boundary coding rule from the start code corresponding to the physical address in the PES data, and determine the part conforming to the frame boundary coding rule as the frame boundary. The framing sub-module 65 is configured to perform framing according to the identified frame boundary to generate the compressed audio and video frames.

本发明实施例提供的技术方案中,根据接收到的信号,生成传输流,从传输流中过滤出音视频码流,所述音视频码流包括打包的基本码流PES数据,将所述PES数据写入内存的多个环形缓冲中,所述PES数据包括至少一个起始码,对所述至少一个起始码在所述多个环形缓冲的位置进行识别,得到所述位置对应的物理地址,将所述物理地址记录到所述内存的起始码缓冲区中,响应于生成的中断通知信号,根据所述物理地址对所述PES数据进行解析生成压缩音视频帧,并将所述压缩音视频帧写入到所述内存中的至少一个帧缓冲区中,减少了由于拷贝压缩音视频帧导致的系统性能下降,提高了组帧速度,减少了延时较长引起的丢帧卡顿。In the technical solution provided by the embodiment of the present invention, a transport stream is generated according to the received signal, and an audio and video code stream is filtered out from the transport stream. The data is written into multiple ring buffers in the memory, the PES data includes at least one start code, the position of the at least one start code in the multiple ring buffers is identified, and the physical address corresponding to the position is obtained , record the physical address in the start code buffer of the memory, and in response to the generated interrupt notification signal, parse the PES data according to the physical address to generate a compressed audio and video frame, and compress the compressed audio and video frames. The audio and video frames are written into at least one frame buffer in the memory, which reduces the system performance degradation caused by copying and compressing the audio and video frames, improves the frame rate, and reduces the frame loss caused by the long delay. .

本发明实施例提供了一种存储介质,所述存储介质包括存储的程序,其中,在所述程序运行时控制所存储介质所在设备执行上述音视频码流的处理方法的实施例。An embodiment of the present invention provides a storage medium, where the storage medium includes a stored program, wherein when the program is run, a device where the stored medium is located is controlled to execute the embodiment of the above-mentioned processing method for audio and video code streams.

本发明实施例提供了一种电子设备,包括存储器、处理器以及存储在所述存储器中并可在所述处理器上运行的计算机程序,所述处理器执行所述计算机程序时实现上述音视频码流的处理方法的实施例。An embodiment of the present invention provides an electronic device, including a memory, a processor, and a computer program stored in the memory and running on the processor, where the processor implements the above-mentioned audio and video when executing the computer program An embodiment of a code stream processing method.

图6为本发明实施例提供的一种电子设备的示意图,如图6所示,该实施例的电子设备20包括:处理器21、存储器22以及存储在存储22中并可在处理器21上运行的计算机程序23,该计算机程序23被处理器21执行时实现实施例中的应用于音视频码流的处理方法,为避免重复,此处不一一赘述。或者,该计算机程序被处理器21执行时实现实施例中应用于音视频码流的处理装置中各模型/单元的功能,为避免重复,此处不一一赘述。FIG. 6 is a schematic diagram of an electronic device according to an embodiment of the present invention. As shown in FIG. 6 , the electronic device 20 in this embodiment includes: a processor 21 , a memory 22 , and a processor 21 that is stored in the storage 22 and can be accessed on the processor 21 . The running computer program 23, when the computer program 23 is executed by the processor 21, implements the processing method applied to the audio and video code stream in the embodiment. To avoid repetition, details are not repeated here. Alternatively, when the computer program is executed by the processor 21, the functions of each model/unit in the apparatus for processing audio and video code streams in the embodiment are implemented. To avoid repetition, details are not repeated here.

电子设备20包括,但不仅限于,处理器21、存储器22。本领域技术人员可以理解,图6仅仅是电子设备20的示例,并不构成对电子设备20的限定,可以包括比图示更多或更少的部件,或者组合某些部件,或者不同的部件,例如电子设备还可以包括输入输出设备、网络接入设备、总线等。The electronic device 20 includes, but is not limited to, a processor 21 and a memory 22 . Those skilled in the art can understand that FIG. 6 is only an example of the electronic device 20, and does not constitute a limitation to the electronic device 20. It may include more or less components than the one shown, or combine some components, or different components For example, the electronic device may also include an input and output device, a network access device, a bus, and the like.

所称处理器21可以是中央处理单元(Central Processing Unit,CPU),还可以是其他通用处理器、数字信号处理器(Digital Signal Processor,DSP)、专用集成电路(Application Specific Integrated Circuit,ASIC)、现场可编程门阵列(Field-Programmable Gate Array,FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件等。通用处理器可以是微处理器或者该处理器也可以是任何常规的处理器等。The so-called processor 21 may be a central processing unit (Central Processing Unit, CPU), and may also be other general-purpose processors, digital signal processors (Digital Signal Processors, DSP), application specific integrated circuits (Application Specific Integrated Circuit, ASIC), Field-Programmable Gate Array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.

存储器22可以是电子设备20的内部存储单元,例如电子设备20的硬盘或内存。存储器22也可以是电子设备20的外部存储设备,例如电子设备20上配备的插接式硬盘,智能存储卡(Smart Media Card,SMC),安全数字(Secure Digital,SD)卡,闪存卡(Flash Card)等。进一步地,存储器22还可以既包括电子设备20的内部存储单元也包括外部存储设备。存储器22用于存储计算机程序以及电子设备所需的其他程序和数据。存储器22还可以用于暂时地存储已经输出或者将要输出的数据。The memory 22 may be an internal storage unit of the electronic device 20 , such as a hard disk or a memory of the electronic device 20 . The memory 22 can also be an external storage device of the electronic device 20, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash memory card (Flash card) equipped on the electronic device 20. Card), etc. Further, the memory 22 may also include both an internal storage unit of the electronic device 20 and an external storage device. The memory 22 is used to store computer programs and other programs and data required by the electronic device. The memory 22 may also be used to temporarily store data that has been or will be output.

所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,上述描述的系统,装置和单元的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the system, device and unit described above may refer to the corresponding process in the foregoing method embodiments, which will not be repeated here.

在本发明所提供的几个实施例中,应该理解到,所揭露的系统,装置和方法,可以通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的,例如,所述单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如,多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或单元的间接耦合或通信连接,可以是电性,机械或其它的形式。In the several embodiments provided by the present invention, it should be understood that the disclosed system, apparatus and method may be implemented in other manners. For example, the apparatus embodiments described above are only illustrative. For example, the division of the units is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components may be combined. Either it can be integrated into another system, or some features can be omitted, or not implemented. On the other hand, the shown or discussed mutual coupling or direct coupling or communication connection may be through some interfaces, indirect coupling or communication connection of devices or units, and may be in electrical, mechanical or other forms.

所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本实施例方案的目的。The units described as separate components may or may not be physically separated, and components displayed as units may or may not be physical units, that is, may be located in one place, or may be distributed to multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution in this embodiment.

另外,在本发明各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。上述集成的单元既可以采用硬件的形式实现,也可以采用硬件加软件功能单元的形式实现。In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically alone, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware, or may be implemented in the form of hardware plus software functional units.

上述以软件功能单元的形式实现的集成的单元,可以存储在一个计算机可读取存储介质中。上述软件功能单元存储在一个存储介质中,包括若干指令用以使得一台计算机装置(可以是个人计算机,服务器,或者网络装置等)或处理器(Processor)执行本发明各个实施例所述方法的部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(Read-Only Memory,ROM)、随机存取存储器(Random Access Memory,RAM)、磁碟或者光盘等各种可以存储程序代码的介质。The above-mentioned integrated units implemented in the form of software functional units can be stored in a computer-readable storage medium. The above-mentioned software functional unit is stored in a storage medium, and includes several instructions to cause a computer device (which may be a personal computer, a server, or a network device, etc.) or a processor (Processor) to execute the methods described in the various embodiments of the present invention. some steps. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, ROM), random access memory (Random Access Memory, RAM), magnetic disk or optical disk and other media that can store program codes .

以上所述仅为本发明的较佳实施例而已,并不用以限制本发明,凡在本发明的精神和原则之内,所做的任何修改、等同替换、改进等,均应包含在本发明保护的范围之内。The above descriptions are only preferred embodiments of the present invention, and are not intended to limit the present invention. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present invention shall be included in the present invention. within the scope of protection.

Claims (10)

1.一种音视频码流的处理方法,其特征在于,所述方法包括:1. a processing method of audio and video code stream, is characterized in that, described method comprises: 根据接收到的信号,生成传输流;Generate a transport stream according to the received signal; 从传输流中过滤出音视频码流,所述音视频码流包括打包的基本码流PES数据;Filter out the audio and video code stream from the transport stream, and the audio and video code stream includes the packaged elementary code stream PES data; 将所述PES数据写入内存的多个环形缓冲中,所述PES数据包括至少一个起始码;Writing the PES data into a plurality of ring buffers in the memory, the PES data including at least one start code; 对所述至少一个起始码在所述多个环形缓冲的位置进行识别,得到所述位置对应的物理地址;Identifying the position of the at least one start code in the plurality of ring buffers to obtain a physical address corresponding to the position; 将所述物理地址记录到所述内存的起始码缓冲区中;recording the physical address in the start code buffer of the memory; 响应于生成的中断通知信号,根据所述物理地址对所述PES数据进行解析生成压缩音视频帧,并将所述压缩音视频帧写入到所述内存中的至少一个帧缓冲区中。In response to the generated interrupt notification signal, the PES data is parsed according to the physical address to generate a compressed audio and video frame, and the compressed audio and video frame is written into at least one frame buffer in the memory. 2.根据权利要求1所述的方法,其特征在于,所述从传输流中过滤出音视频码流,包括:2. The method according to claim 1, wherein, filtering out the audio and video code stream from the transport stream, comprising: 通过设置的包标识符PID对所述传输流进行过滤,生成所述音视频码流。Filter the transport stream through the set packet identifier PID to generate the audio and video stream. 3.根据权利要求1所述的方法,其特征在于,所述响应于生成的中断通知信号,根据所述物理地址对所述PES数据进行解析生成压缩音视频帧之前,还包括:3. method according to claim 1, is characterized in that, described in response to the interrupt notification signal of generation, before described PES data is parsed according to described physical address to generate compressed audio and video frames, also comprises: 对所述至少一个起始码在所述多个环形缓冲的个数进行识别,生成每个所述环形缓冲对应的所述起始码的个数;Identifying the number of the at least one start code in the plurality of ring buffers, and generating the number of the start codes corresponding to each of the ring buffers; 将所述起始码的个数记录到对应的所述环形缓冲中。Record the number of the start codes into the corresponding ring buffer. 4.根据权利要求1所述的方法,其特征在于,所述将所述物理地址记录到内存的起始码缓冲区中之前,还包括:4. The method according to claim 1, wherein before the recording the physical address into the start code buffer of the memory, the method further comprises: 分配一个指定大小的缓冲区,将所述指定大小的缓冲区作为所述起始码缓冲区。Allocate a buffer of a specified size, and use the buffer of the specified size as the start code buffer. 5.根据权利要求1所述的方法,其特征在于,所述将所述压缩音视频帧写入到内存中的至少一个帧缓冲区中,包括:5. The method according to claim 1, wherein the writing of the compressed audio and video frames into at least one frame buffer in the memory comprises: 判断采用独立缓冲方式进行缓冲或者采用非独立缓冲方式进行缓冲;Determine whether to use independent buffering for buffering or non-independent buffering for buffering; 若判断出采用所述独立缓冲方式进行缓冲,则将每个压缩音视频帧写入对应的帧缓冲区中;If it is determined that the independent buffering mode is used for buffering, each compressed audio and video frame is written into the corresponding frame buffer; 若判断出采用非独立缓冲方式进行缓冲,则将全部的所述压缩音视频帧写入一个帧缓冲区中。If it is determined that the non-independent buffering mode is used for buffering, all the compressed audio and video frames are written into a frame buffer. 6.根据权利要求1所述的方法,其特征在于,所述对所述至少一个起始码在所述多个环形缓冲的位置进行识别之前,还包括:6. The method according to claim 1, wherein before the identifying the positions of the at least one start code in the plurality of ring buffers, the method further comprises: 根据码流的编码规范设置至少一个起始码。Set at least one start code according to the encoding specification of the code stream. 7.根据权利要求3所述的方法,其特征在于,所述对所述PES数据进行解析生成压缩音视频帧,包括:7. The method according to claim 3, wherein the described PES data is analyzed to generate compressed audio and video frames, comprising: 获取所述环形缓冲中的所述起始码的个数;obtaining the number of the start codes in the ring buffer; 在所述起始码缓冲区中读取与所述起始码个数对应数量的所述起始码在环形缓冲中的物理地址;Reading the physical addresses of the start codes in the ring buffer corresponding to the number of the start codes in the start code buffer; 根据所述物理地址在环形缓冲中查找出所述物理地址对应的起始码;Find out the start code corresponding to the physical address in the ring buffer according to the physical address; 在所述PES数据中,从所述物理地址对应的起始码开始检测出符合帧边界编码规则的部分,并将符合帧边界编码规则的部分确定为帧边界;In the PES data, the start code corresponding to the physical address starts to detect the part that meets the frame boundary coding rule, and the part that meets the frame boundary coding rule is determined as the frame boundary; 根据识别出的帧边界进行组帧,生成所述压缩音视频帧。Framing is performed according to the identified frame boundaries to generate the compressed audio and video frames. 8.一种音视频码流的处理装置,其特征在于,包括:8. a processing device of audio and video code stream, is characterized in that, comprises: 生成模块,用于根据接收到的信号,生成传输流;The generation module is used to generate the transport stream according to the received signal; 过滤模块,用于从传输流中过滤出音视频码流,所述音视频码流包括PES数据;A filtering module, configured to filter out an audio and video code stream from the transport stream, where the audio and video code stream includes PES data; 第一写入模块,用于将所述PES数据写入内存的多个环形缓冲中,所述PES数据包括至少一个起始码;a first writing module, configured to write the PES data into multiple ring buffers of the memory, the PES data including at least one start code; 第一识别模块,用于对所述至少一个起始码在所述多个环形缓冲的位置进行识别,得到所述位置对应的物理地址;a first identification module, configured to identify the position of the at least one start code in the plurality of ring buffers to obtain a physical address corresponding to the position; 第一记录模块,用于将所述物理地址记录到所述内存的起始码缓冲区中;a first recording module, for recording the physical address in the start code buffer of the memory; 解析模块,用于响应于生成的中断通知信号,根据所述物理地址对所述PES数据进行解析生成压缩音视频帧;A parsing module, configured to parse the PES data according to the physical address to generate a compressed audio and video frame in response to the generated interrupt notification signal; 第二写入模块,用于将所述压缩音视频帧写入到所述内存中的至少一个帧缓冲区中。The second writing module is configured to write the compressed audio and video frames into at least one frame buffer in the memory. 9.一种存储介质,其特征在于,所述存储介质包括存储的程序,其中,在所述程序运行时控制所存储介质所在设备执行权利要求1至7中任一项所述的音视频码流的处理方法。9. a storage medium, it is characterised in that the storage medium comprises a stored program, wherein, when the program is run, the device where the stored medium is controlled to execute the audio-video code described in any one of claims 1 to 7 Stream processing method. 10.一种电子设备,其特征在于,包括存储器、处理器以及存储在所述存储器中并可在所述处理器上运行的计算机程序,所述处理器执行所述计算机程序时实现如权利要求1至7任一项所述的音视频码流的处理方法。10. An electronic device, characterized in that it comprises a memory, a processor and a computer program stored in the memory and executable on the processor, the processor implementing the computer program as claimed in the claims The method for processing audio and video code streams according to any one of 1 to 7.
CN202111587352.8A 2021-12-23 2021-12-23 A method, device and electronic device for processing audio and video code streams Active CN114339378B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111587352.8A CN114339378B (en) 2021-12-23 2021-12-23 A method, device and electronic device for processing audio and video code streams

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111587352.8A CN114339378B (en) 2021-12-23 2021-12-23 A method, device and electronic device for processing audio and video code streams

Publications (2)

Publication Number Publication Date
CN114339378A true CN114339378A (en) 2022-04-12
CN114339378B CN114339378B (en) 2025-05-02

Family

ID=81055389

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111587352.8A Active CN114339378B (en) 2021-12-23 2021-12-23 A method, device and electronic device for processing audio and video code streams

Country Status (1)

Country Link
CN (1) CN114339378B (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115174969A (en) * 2022-07-01 2022-10-11 抖音视界(北京)有限公司 Video pushing method and device and storage medium
CN115714879A (en) * 2022-11-17 2023-02-24 展讯通信(上海)有限公司 Data decoding method, device, equipment and storage medium

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1368681A (en) * 2001-02-07 2002-09-11 北京算通数字技术研究中心有限公司 Date receiving method based on CPU able to receive basic data stream
CN1960335A (en) * 2005-10-31 2007-05-09 恩益禧电子股份有限公司 Stream data processor
CN101193289A (en) * 2006-11-22 2008-06-04 中兴通讯股份有限公司 A real time conversion method from MPEG-4 transmission code stream to Internet stream media alliance stream
CN101399993A (en) * 2007-09-29 2009-04-01 奇景光电股份有限公司 Video and audio synchronization device and method
CN101404764A (en) * 2008-10-30 2009-04-08 宁波中科集成电路设计中心有限公司 Internal memory management method in audio/video decoding course
CN101540899A (en) * 2008-03-19 2009-09-23 上海贝尔阿尔卡特股份有限公司 I frame resolution method and I frame resolver in streaming media system

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1368681A (en) * 2001-02-07 2002-09-11 北京算通数字技术研究中心有限公司 Date receiving method based on CPU able to receive basic data stream
CN1960335A (en) * 2005-10-31 2007-05-09 恩益禧电子股份有限公司 Stream data processor
CN101193289A (en) * 2006-11-22 2008-06-04 中兴通讯股份有限公司 A real time conversion method from MPEG-4 transmission code stream to Internet stream media alliance stream
CN101399993A (en) * 2007-09-29 2009-04-01 奇景光电股份有限公司 Video and audio synchronization device and method
CN101540899A (en) * 2008-03-19 2009-09-23 上海贝尔阿尔卡特股份有限公司 I frame resolution method and I frame resolver in streaming media system
CN101404764A (en) * 2008-10-30 2009-04-08 宁波中科集成电路设计中心有限公司 Internal memory management method in audio/video decoding course

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115174969A (en) * 2022-07-01 2022-10-11 抖音视界(北京)有限公司 Video pushing method and device and storage medium
CN115714879A (en) * 2022-11-17 2023-02-24 展讯通信(上海)有限公司 Data decoding method, device, equipment and storage medium
CN115714879B (en) * 2022-11-17 2024-10-08 展讯通信(上海)有限公司 Data decoding method, device, equipment and storage medium

Also Published As

Publication number Publication date
CN114339378B (en) 2025-05-02

Similar Documents

Publication Publication Date Title
JP4689872B2 (en) Digital video stream decoding method and apparatus by pseudo header insertion in digital video system
US7558806B2 (en) Method and apparatus for buffering streaming media
US10469915B2 (en) Apparatus and method for delivering and receiving multimedia data in hybrid network
CN110996160A (en) Video processing method and device, electronic equipment and computer readable storage medium
CN114339378A (en) Audio and video code stream processing method and device and electronic equipment
US8190582B2 (en) Multi-processor
CN113747171B (en) Self-recovery video decoding method
US6907481B2 (en) System for bit-rate controlled digital stream playback and method thereof
CN112911390B (en) Video data playing method and terminal equipment
CN110417811A (en) The method and device of encoding abit stream compression
CN108093258B (en) Code stream data decoding method, computer device and computer readable storage medium
WO2023083213A1 (en) Data decoding method and apparatus, electronic device and readable storage medium
KR20010102101A (en) Device and method for processing information and recorded medium
WO2021254375A1 (en) Video partitioning method, transfer method, server, adaptor and storage medium
US6625218B1 (en) Audio/video separator including a user data start address register
EP3678368B1 (en) Video streaming batch
EP4075814A1 (en) Mp4 file virtual mss fragmentation method, mss adapter, media server, and storage medium
US10354695B2 (en) Data recording control device and data recording control method
US20160035388A1 (en) Video chunking for robust, progressive uploading
CN117041227A (en) Video stream read-write control method, display method and related equipment
CN119155290A (en) File encapsulation method, file playing method and related products
CN109104625A (en) A kind of integrated medium module based on COM-Express standard
CN103647979A (en) Method and device for processing remote subtitles of intelligent television and media player thereof
CN120856850A (en) Video recording method, playback method, device and equipment
US7715402B2 (en) Method and device for processing digital data

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant