Offline adaptive audio streaming and integrity protection method based on terminal cache

By encoding audio frames in the terminal cache for parallel processing and incremental hash verification, the problem of transmitting real-time audio streams under unstable mobile networks is solved, achieving complete data retention and reliable transmission. It is suitable for mobile audio acquisition devices such as law enforcement recorders and walkie-talkies.

CN123184797APending Publication Date: 2026-11-27HANGZHOU JINGWEI INTELLIGENT TECHNOLOGY CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202611684527.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-10-29
Publication Date
2026-11-27

AI Technical Summary

Technical Problem

Existing technologies cannot simultaneously achieve low-latency transmission, long-term offline data retention, and end-to-end integrity verification in real-time audio streaming. Especially when mobile communication networks are unstable, recording data is easily lost or cannot be accurately resumed.

Method used

The method employs terminal caching to encode audio data into frames with continuously increasing sequence numbers. It then uses dual-path parallel processing, with one path uploading in real time and the other writing to the terminal's local persistent storage medium. By combining frame-level sequence numbers with server-side breakpoint records, it achieves accurate resume transmission and uses incremental hashing to verify the integrity of the entire process.

Benefits of technology

It achieves complete retention of audio data during long-term network outages, accurately locates transmission interruption points, reduces invalid data transmission, ensures reliable availability of recording data and low latency for real-time transmission, and adapts to frequent fluctuations in mobile networks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123184797A_ABST
    Figure CN123184797A_ABST
Patent Text Reader

Abstract

The application discloses a kind of based on terminal cache's network break self-adapting audio stream transmission and integrity protection method, audio coding generates ordered frame after synchronization two-way output, one real-time upload cloud, one is stored into terminal memory card.Normal transmission time relies on frame confirmation message maintenance sending window, dynamic adjustment retransmission strategy.Through timeout and heartbeat detection identification network break, network break only continues local cache, stops network sending.Network recovery, terminal initiates continuation request, server calls breakpoint information saved persistently locates first missing frame, terminal reads local cache and supplements transmission, while preferentially guaranteeing new acquisition audio transmission.When session ends, terminal and server are synchronized to use incremental hash calculation check value, and consistent comparison determines audio integrity.The application can be long time without data loss by relying on terminal memory card in network break, and uses streaming hash to complete real-time audio whole-process verification.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of real-time audio transmission technology, specifically relating to a method for adaptive audio stream transmission and integrity protection based on terminal caching when the network is disconnected. Background Technology

[0002] In remote real-time recording scenarios, data acquisition devices such as voice recorders, law enforcement recorders, and handheld walkie-talkies generally rely on mobile communication networks to upload real-time audio data to a cloud service platform. The mainstream approach is to compress the raw audio into fixed-length encoded frames, commonly using the Opus encoding format, with a single frame duration typically set to 60 milliseconds, and then transmit the data frame by frame via a WebSocket long connection. For abnormal scenarios such as network interruptions and signal loss, the following processing solutions are currently mainly adopted.

[0003] (1) Full retransmission. After the device detects a network interruption, it temporarily stores the unsent audio data in a memory buffer. After the network is restored, all data is retransmitted from the beginning of the buffer.

[0004] (2) File-level resume upload. After recording the audio as a complete file, it is uploaded in fixed-size chunks, each carrying a byte offset. The server records the maximum offset received. This solution is suitable for scenarios where uploading is done after recording is complete.

[0005] (3) IoT data backup and retransmission. For example, patent document CN202410928093 discloses a method for backing uplink frame data backup and retransmission. When the LoRaWAN gateway is disconnected from the server, the uplink frame data is backed up to an SQL database, and after restoration, the data is extracted from the database for transparent transmission. This solution is aimed at non-real-time scenarios of IoT sensor data, does not involve the maintenance of the timing relationship of audio frames and integrity verification, and the method of backing up to an SQL database is insufficient for writing high bitrate audio streams.

[0006] A comprehensive analysis reveals the following shortcomings in the existing technology:

[0007] (1) Real-time transmission and data preservation during network outages are incompatible. Real-time transmission schemes using memory caching are limited by hardware memory capacity, and recording data will inevitably be lost in long-term network outage scenarios. The file block resuming transmission scheme only supports batch uploading after recording is completed, and does not support real-time services that record and transmit continuously without interruption.

[0008] (2) Most existing resume mechanisms use complete files and fixed data blocks as breakpoint markers, failing to fully utilize the naturally continuously increasing sequence number attribute of audio frames, and thus cannot locate the specific missing single frame content. After the network is restored, large-scale repeated transmission is necessary, resulting in a large amount of data already delivered to the server being sent a second time.

[0009] (3) Lack of incremental integrity verification methods adapted to real-time streams. The total data length during the real-time audio stream recording stage is unknown. Traditional solutions can only wait until all audio is transmitted and then calculate the hash value for the complete file to verify integrity. If a network interruption or device restart occurs during recording, it is impossible to verify the accuracy of the transmitted segments in segments.

[0010] (4) The cache storage medium is not compatible with the high-frequency writing characteristics of audio. Existing IoT backup solutions generally use lightweight databases such as SQLite as local cache carriers. Database storage relies on indexes and transaction mechanisms to complete data writing. Frequent small block writing will cause a lot of performance loss and cannot match the writing rhythm of the millisecond-level continuous output of audio streams.

[0011] Therefore, a new method for audio stream transmission and integrity protection after network outage is needed. Summary of the Invention

[0012] To address the technical challenges of existing technologies that real-time audio streaming cannot simultaneously achieve low-latency transmission, long-term network outage data retention, and end-to-end integrity verification, this invention overcomes the capacity limitations of memory cache with large-capacity storage, achieves accurate resume transmission by relying on frame-level sequence numbers and server-side breakpoint records, and implements complete verification through streaming incremental hashing.

[0013] This invention proposes a method for adaptive audio stream transmission and integrity protection based on terminal caching when the network is disconnected. It is implemented using an audio acquisition terminal and a cloud server, and includes the following steps: S1. The audio acquisition terminal encodes the acquired audio data into audio frames with continuously increasing sequence numbers, and synchronously splits them into two parallel processing streams. One stream is uploaded to the cloud server in real time, and the other stream is written to the terminal's local persistent storage medium. S2. During normal transmission, the cloud server confirms the reception status according to the frame sequence number and sends back an acknowledgment message. The audio acquisition terminal maintains the sending sliding window based on the acknowledgment message and dynamically adjusts the retransmission strategy in combination with the network status. S3. Network interruption is identified through a dual mechanism of frame timeout statistics and heartbeat detection. After the network is disconnected, the network transmission link is suspended to keep audio acquisition and local buffer running continuously. S4. After the network is restored, the connection is rebuilt. The audio acquisition terminal initiates a resume request. The cloud server retrieves the breakpoint record that is persistently stored independently of the connection lifecycle to locate the sequence number of the first missing audio frame. S5. The audio acquisition terminal reads the missing frames from the local storage medium of the terminal for retransmission. During the scheduling process, the real-time transmission of newly acquired audio is prioritized. After the retransmission catches up with the real-time frames, the dual-path parallel transmission is seamlessly restored. S6. The terminal and the server synchronously update the incremental hash calculation status frame by frame. The intermediate hash state is persistently saved with the breakpoint record. When the session ends, both ends calculate the final check value respectively. If they match, the audio is determined to be complete. S7. After a normal session is completed, delete the cache file of the corresponding session in the local storage medium of the terminal; if the device terminates abnormally, scan the residual cache file after restarting the device, and retain the ability to resume transmission for valid sessions.

[0014] Preferably, S1 includes: S11. The audio acquisition terminal establishes an encrypted long connection with the cloud server. The terminal sends a session initiation signaling message, carrying the global file identifier, transmission mode category and audio encoding parameters. The server creates an independent state instance for the current session, initializes the expected received frame sequence number and verification context, and returns a response message carrying the session identifier and the initial receiving window. S12. The terminal collects raw audio data, divides it into blocks of fixed duration, generates audio frames through compression encoding, assigns a continuously increasing globally unique frame sequence number to each frame, and synchronously initializes the streaming hash calculation context. S13. The encoded audio frame is sent to the circular buffer queue and read independently and in parallel by the upload task thread and the cache task thread. The upload task encapsulates the data into a transmission message and sends it to the server in a non-blocking manner. The cache task writes the audio frame to the terminal's local storage medium according to the preset frame storage format. The storage frame is address-aligned according to the maximum space occupied by a single frame, and the storage offset is calculated by multiplying the frame sequence number by the space occupied by a single frame.

[0015] Preferably, S2 includes: S21. After receiving the audio frame, the cloud server processes it according to the frame sequence number and the current receiving status. Duplicate frames are directly returned for confirmation, out-of-order frames are temporarily stored in the out-of-order buffer, and consecutive frames are written to storage and the streaming hash context is updated synchronously. S22. After the cloud server finishes processing the consecutive frames, it returns an acknowledgment message to the terminal carrying the largest sequence number that has been received consecutively. The audio acquisition terminal maintains a sliding window for sending. After receiving the acknowledgment message, it slides the left boundary of the window, releases the storage resources of the confirmed frames, and dynamically adjusts the window size according to network latency and packet loss status. S23. The audio acquisition terminal starts a retransmission timeout timer for each sent frame and dynamically calculates the timeout threshold based on the network round-trip delay sampling value. When a timeout is triggered and the number of retransmissions has not reached the upper limit, backoff retransmission is performed. When multiple consecutive frames trigger timeouts and there is no heartbeat response, the network interruption judgment process is entered.

[0016] Preferably, S3 includes: S31. When a preset number of consecutive audio frames trigger a retransmission timeout and no corresponding acknowledgment message is received, and the periodically sent heartbeat message does not receive a response from the server within a preset time limit, it is determined that the network is interrupted, the current sending window state is frozen, and new audio frames are stopped from being sent to the network. S32. After determining that the network is disconnected, it automatically switches to pure buffer working mode. The audio acquisition, encoding and frame sequence number allocation process continues to run. All new audio frames are written to the terminal's local storage medium. At the same time, it periodically initiates network detection to verify network connectivity. Once the network is detected to be restored, it immediately starts the resume transmission process.

[0017] Preferably, S4 includes: S41. After the network is restored and connectivity verification is successful, the audio acquisition terminal rebuilds the encrypted long connection with the cloud server, sends a resume signaling message, carrying the file identifier of the original session and the maximum frame sequence number generated by the current terminal. S42. The cloud server retrieves the breakpoint record from persistent storage based on the file identifier. This record is saved independently of the original connection's lifecycle. Based on the confirmed consecutive maximum sequence number and the out-of-order frame sequence number bitmap, it traverses and locates the first missing frame sequence number, while loading the intermediate calculation state of the streaming hash. S43. The cloud server encapsulates the sequence number of the first missing frame, the number of frames to be retransmitted, and the list of received out-of-order frame sequence numbers into a resume response message and returns it to the terminal. If there is no corresponding breakpoint record, it returns a reset flag to notify the terminal to start the transmission from the beginning.

[0018] Preferably, in step S4, the cloud server retrieves the persistently stored breakpoint record based on the file identifier. The breakpoint record is saved independently of the original connection's lifecycle. Based on the confirmed consecutive maximum sequence number and the out-of-order frame sequence number bitmap, the server locates the first missing frame sequence number and loads the intermediate calculation state of the streaming hash. The server feeds back the first missing frame sequence number, the number of frames to be retransmitted, and the list of received out-of-order frame sequence numbers to the terminal. If there is no corresponding breakpoint record, the server is notified to start the transmission from the beginning.

[0019] Preferably, the breakpoint record is persistently stored by appending logs and periodically taking snapshots. When the server restarts, the breakpoint state of the session is restored by taking snapshots and replaying logs.

[0020] Preferably, S5 includes: S51. The audio acquisition terminal parses the continuation response message, locates the corresponding audio frame in the local storage medium of the terminal according to the mapping relationship between the frame sequence number and the storage offset, skips the out-of-order frames that have been received by the server, extracts the unreceived frames to form a retransmission queue, and reads the local cached frames using a batch pre-read mechanism, continuously reading a preset number of audio frames each time and storing them in the memory buffer. S52. A bandwidth control mechanism and priority scheduling strategy are adopted to allocate high priority to newly acquired real-time frames and low priority to retransmission frames, which occupy the remaining bandwidth of real-time transmission. When the sequence number of the retransmission frame catches up with the sequence number of the latest real-time generated frame, the system switches back to the normal dual-path parallel transmission mode.

[0021] Preferably, the cloud server performs idempotent verification on the retransmitted frames. For frames with sequence numbers less than the currently confirmed maximum sequence number, an acknowledgment message is returned directly. For frames falling within the out-of-order buffer range, it checks whether they already exist. If they do not exist, they are added to the buffer. For new consecutive sequence number frames, a disk write operation is performed, and the breakpoint record and hash status are updated synchronously. When frames in the out-of-order buffer range form a consecutive range, the receiving sequence numbers are advanced in batches, and the status is updated.

[0022] Preferably, the S6 includes: S61. The audio acquisition terminal and the cloud server follow the same hash calculation rules. The pure audio encoded payload is used as input, and the hash context is updated frame by frame in ascending order of frame number. The intermediate hash state can be serialized and persistently stored. After the network is restored, it is loaded and the calculation is continued to complete the verification of continuity across multiple network outages. S62. After the terminal stops audio acquisition, it generates a termination frame with an end marker and sends it to the transmission and buffering link. After all frames to be sent have been transmitted, the terminal calculates the final hash check value, encapsulates it into an end signaling message, and sends it to the server. S63. After receiving all consecutive frames, the server calculates the final hash value and compares it with the terminal hash value carried in the end signaling. If the comparison matches, the audio data is determined to be complete and valid. If the comparison does not match, the segmentation verification mechanism is activated. The data is divided into segments according to a fixed number of frames and compared one by one. After locating the abnormal segment, it is retransmitted in a targeted manner.

[0023] The present invention has the following beneficial effects: (1) The present invention uses a terminal storage card as a persistent storage medium, which can support the complete retention of audio data under long-term network outages, and completely get rid of the capacity constraints of memory cache. When the network is disconnected, the audio acquisition work will not be interrupted, and new audio frames will be continuously written to local storage, without data overflow or recording loss.

[0024] (2) This invention utilizes the inherent characteristic of audio frames having continuously increasing sequence numbers to achieve precise frame-level breakpoint resumption. After network recovery, it can directly locate the first missing audio frame after the transmission interruption. The device only resends the frame data that was not successfully received to the server, reducing invalid data transmission.

[0025] (3) This invention employs incremental hash calculation logic to provide full-process integrity verification capabilities for real-time streaming audio, ensuring the reliability and usability of the evidence-gathering audio. The device and server synchronously update the hash calculation status frame by frame. Even if multiple network interruptions occur during recording, the server's breakpoint records will retain intermediate hash calculation results, allowing the verification process to continue once the network is restored. Once the recording ends, a comparison of the final hash values ​​at both ends confirms that the entire audio recording was neither lost nor tampered with.

[0026] (4) The dual-path parallel write architecture does not interfere with each other, balancing real-time transmission and cache reliability. After audio acquisition, it is synchronously split to the network upload link and the local cache link, and the two processing channels are decoupled and operate independently. The two links rely on the ring buffer for decoupling scheduling to maintain a low-latency transmission standard of 60 milliseconds per frame. (5) The server persistently retains the breakpoint state, and transmission can be quickly resumed after network reconnection. The server saves a separate breakpoint record checkpoint for each recording session. Checkpoint persistence is independent of the connection lifecycle. The connection context is cleaned up after the network disconnection timeout but not the checkpoint, ensuring that the server state is complete when the connection is restored.

[0027] This invention is compatible with various mobile audio acquisition terminals such as law enforcement recorders, walkie-talkies, and recording devices, and can be widely used in real-time recording and evidence preservation scenarios where mobile communication signals are unstable, such as field law enforcement, outdoor inspections, and on-site intercoms. Attached Figure Description

[0028] Figure 1 This is a diagram illustrating the method steps of an embodiment of the present invention; Figure 2 This is a block diagram of the overall architecture of an embodiment of the present invention; Figure 3 This is a flowchart of a method according to an embodiment of the present invention. Detailed Implementation

[0029] To further understand the present invention, embodiments of the present invention are described below in conjunction with examples. However, it should be understood that these descriptions are only for further illustrating the features and advantages of the present invention, and not for limiting the scope of the claims of the present invention.

[0030] The terminal-cached, network-disconnect adaptive audio stream transmission and integrity protection method described in this embodiment uses a large-capacity local storage card on the terminal as a persistent cache carrier. It unifies the timing benchmark for real-time transmission and local storage through a frame-level sequence number system, achieves accurate resume transmission by combining a server-side breakpoint persistence mechanism, and ensures data integrity through continuous streaming hash verification across network disconnections. Figures 1-3 As shown, the method includes the following steps: S1. Session initialization and dual-path parallel transmission start-up.

[0031] S11. Session Establishment and Transmission Mode Negotiation. After the audio acquisition device attaches to the mobile communication network, it establishes an encrypted WebSocket long connection with the cloud server based on the transport layer security protocol. The device sends a START session initiation signaling message to the server, which carries a globally unique file identifier, a transmission mode field, audio encoding parameters, and the maximum payload length per frame. There are two transmission modes: streaming mode is suitable for real-time scenarios where recording and uploading are done simultaneously, and the total number of transmission frames dynamically increases with the recording process; file mode is suitable for scenarios where recording is completed and then uploaded in batches, and the signaling message synchronously carries the total number of frames and a pre-calculated checksum of the complete audio.

[0032] After receiving the START signaling, the server creates an independent state instance for the current session, initializes the next expected receive frame sequence number to 0, initializes the verification context for the corresponding transmission mode, allocates session resources, and returns a START_ACK response to the device, which carries the server session identifier and the initial receive window size.

[0033] S12. Audio Acquisition, Encoding, and Frame Number Allocation. The device acquires raw pulse-code modulated audio data through a microphone, divides the audio data into blocks of 60 milliseconds, and uses the Opus encoding algorithm to compress and encode each block, generating encoded frames of the corresponding length. After encoding, the device assigns a continuously increasing frame number to each frame, starting from 0 and incrementing frame by frame. Frame numbers within the same session are globally unique and consecutive, without skipped or duplicate numbers.

[0034] During the encoding phase, the device synchronously initializes the streaming hash calculation context, using the SHA-256 hash algorithm. After each frame is encoded, the device inputs the pure Opus encoded payload of that frame into the hash context for incremental updates. The calculation process does not introduce any other protocol headers, tag fields, or padding bytes, ensuring that the hash calculation benchmarks on the device and server sides are completely consistent.

[0035] S13. Dual-path parallel write execution. Encoded audio frames are sent to a circular buffer queue, where they are read and processed in parallel by two independent consumer threads: the upload task and the cache task. The two paths do not block each other. The upload task retrieves audio frames from the queue in order, encapsulates them into DATA transmission messages, and sends them to the server via a WebSocket connection. The sending process uses a non-blocking mode; the next frame is processed immediately after a single frame is sent, without waiting for an acknowledgment message, ensuring low latency for real-time transmission.

[0036] The caching task synchronously retrieves identical audio frames from the queue and writes them to the device's local TF memory card according to a preset frame storage format. The stored frame uses a fixed header plus a variable payload structure. The header consists of a 4-byte frame sequence number, a 2-byte payload length, a 1-byte flag, and a 1-byte reserved field, totaling 8 bytes. Following the header is the variable-length Opus-encoded audio payload. During storage, address alignment is performed based on the maximum space occupied by a single frame, set to 264 bytes (8-byte header plus 256-byte maximum payload). The storage offset of any frame can be directly calculated by multiplying the frame sequence number by the maximum space occupied by a single frame, achieving constant-time random frame positioning without the need to build an additional index file.

[0037] S2, Frame-level transmission confirmation and sliding window management.

[0038] S21. Server-side Frame Reception and Status Update. After receiving the DATA message from the device, the server parses it to obtain the frame sequence number and audio payload. Different processing logic is executed based on the relationship between the sequence number and the current reception status. If the frame sequence number is less than the currently confirmed maximum consecutive sequence number, it is determined to be a duplicate frame, and an acknowledgment message is returned directly without disk write operation. If the frame sequence number is greater than the expected next frame sequence number, it is determined to be an out-of-order frame, and it is temporarily stored in the out-of-order frame buffer, awaiting completion of any missing frames before unified processing. If the frame sequence number is exactly the same as the expected next frame sequence number, the audio payload is written to persistent storage, the streaming hash context is updated synchronously, and then the expected sequence number is incremented. When consecutive received frames appear in the out-of-order buffer, the server updates the expected sequence number in batches, writes frames within the consecutive interval to disk, and updates the hash status, reducing the performance overhead caused by frequent disk operations.

[0039] S22. Acknowledgment Message Feedback and Sliding Window Maintenance. After processing each frame or batch processing a group of consecutive frames, the server returns an ACK acknowledgment message to the device, carrying the sequence number of the currently continuously received frame. The device maintains a sending sliding window, containing all sent but unacknowledged frames. Upon receiving an ACK message, the device moves the left boundary of the window after the maximum acknowledgment sequence number carried in the message, releasing the memory space occupied by the corresponding frame. The window size is dynamically adjusted according to the real-time network status. When the network round-trip latency is stable and the packet loss rate is low, the window is gradually expanded to increase transmission throughput; when network congestion occurs and latency jitter increases, the window is gradually shrunk to avoid data accumulation exacerbating the network burden.

[0040] S23. Dynamic Retransmission Timeout Calculation. The device starts an independent retransmission timeout timer for each transmitted frame, with an initial timeout value set to 200 milliseconds. Upon receiving an acknowledgment message for each frame, the device calculates the network round-trip latency for the current sample. The Jacobson-Karels algorithm is used to smooth the round-trip latency and latency deviation. The final retransmission timeout is calculated by adding four times the latency deviation to the smoothed round-trip latency. The lower limit of the timeout is set to 200 milliseconds, and the upper limit is set to 5 seconds to adapt to the latency fluctuations of mobile networks and avoid misjudgments or untimely retransmissions. When the timer for a frame times out and the retransmission count has not reached the upper limit, the device performs exponential backoff retransmission for that frame, and the retransmitted frame sets the corresponding retransmission flag. If multiple consecutive frames trigger timeouts and there is no heartbeat response, the network interruption determination process is initiated.

[0041] S3, switching between network disconnection detection and pure cache mode.

[0042] S31. Network Interruption Determination. The device simultaneously determines the network connection status through a dual mechanism of frame-level timeout statistics and heartbeat detection. When five consecutive frames trigger retransmission timeouts and no acknowledgment messages are received, and no heartbeat response is received within a preset period after the heartbeat message is sent, the device formally determines that the network is interrupted.

[0043] Upon determining a network interruption, the device stops the frame transmission logic during the network reconnection process, freezes the current transmission window state, and ceases sending new audio frames to the network side to avoid sending invalid data and increasing the processing pressure after network recovery.

[0044] S32. Pure caching mode operation. After a network interruption, the device automatically switches to pure caching mode. Audio acquisition, encoding, and frame sequence number allocation continue unaffected by network status; all newly added audio frames are sent to the circular buffer. The upload task is suspended, while only the caching task continues, writing all newly generated audio frames sequentially to the local TF card, ensuring all acquired audio data is persistently stored. During the cache writing process, the device continuously monitors the network signal status, periodically initiating network probes to verify the mobile communication network's attachment status and server connectivity. Once network recovery is detected, the resume transmission process is immediately initiated.

[0045] S4. Network recovery and breakpoint negotiation.

[0046] S41. Connection Re-establishment and Resumption Request. Once the device detects that the mobile communication network has been restored and the connectivity verification with the server is successful, it re-establishes the encrypted WebSocket connection with the server. The device sends a RESUME resumption signaling message to the server, carrying the file identifier of the original session and the maximum frame sequence number currently generated by the device, facilitating the server's rapid matching of session states.

[0047] S42. Server-side breakpoint location algorithm. After receiving the RESUME signaling, the server retrieves the checkpoint record of the corresponding session based on the file identifier. This record is persisted independently of the original WebSocket connection's lifecycle, with a default retention period of 30 days. Even if the original connection is cleaned up by the server due to prolonged inactivity, the breakpoint record remains intact. The data structure of the checkpoint record is shown in Table 1.

[0048] Table 1. Data structure of heckpoint records

[0049] Breakpoint location is based on the continuity of frame sequence numbers, and the specific execution steps are as follows: (1) Load the baseline state in the checkpoint, read the maximum consecutively confirmed frame sequence number next_seq, and load the sequence number bitmap of the out-of-order frame buffer. Mark all received but not consecutive interval discrete frame sequence numbers in the bitmap.

[0050] (2) Starting from next_seq, traverse the sequence number bitmap backward to find the first unmarked frame number and determine it as first_missing_seq, that is, the first missing frame number.

[0051] (3) Count the total number of all frames not marked by the bitmap between first_missing_seq and the maximum frame sequence number reported by the device, and use it as the number of frames to be retransmitted; in streaming mode, since the total length is unknown, the number of frames to be retransmitted is marked as the maximum value, indicating that real-time frames need to be continuously received.

[0052] (4) Read the intermediate serialization state of the streaming hash from the checkpoint, including the current hash register value, the number of bytes processed, and the message block buffer that is not filled, for subsequent hash continuation calculation after retransmission.

[0053] Checkpoints use an append-only log writing and periodic snapshots for persistence. Each time the state is updated, the change record is appended to the log file, and a full snapshot is generated at fixed intervals. When the server restarts, the breakpoint state of all sessions is restored through snapshot and log replay, ensuring no data loss after server failure recovery.

[0054] S43. Breakpoint Information Feedback. The server encapsulates the sequence number of the first missing frame, the number of frames to be retransmitted, and a list of received out-of-order frame sequence numbers into a RESUME_ACK message and returns it to the device. If the server does not have a checkpoint record for the corresponding session, it returns a reset flag, notifying the device to retransmit from frame 0.

[0055] S5 seamlessly integrates local cache retransmission with real-time streaming.

[0056] S51. Buffered Frame Reading and Retransmission Queue Construction. After receiving the RESUME_ACK message, the device parses it to obtain the sequence number of the first missing frame and a list of received out-of-order frames. Based on the mapping formula between frame sequence numbers and storage offsets, the physical storage location of the corresponding frame is directly located in the TF memory card, and all buffered frames are traversed in ascending order. During the traversal, out-of-order frames marked as received are skipped, and only unreceived frames are extracted to build a retransmission queue, reducing redundant data transmission.

[0057] The reading process employs a batch pre-read mechanism, reading 32 consecutive frames at a time and storing them in the memory buffer to reduce the number of random reads from the TF card and improve retransmission efficiency. During the reading of each frame, the length field of the frame header and the integrity of the payload are simultaneously verified. Corrupted frames that fail verification are marked as invalid and skipped, and subsequently supplemented through a secondary retransmission mechanism.

[0058] S52. Scheduling and Sending of Retransmission and Real-Time Frames. The device uses a token bucket algorithm for bandwidth management and sends data according to a priority scheduling strategy. Newly acquired frames are assigned to high-priority token buckets to ensure that the transmission latency of real-time frames does not exceed 60 milliseconds, maintaining a low-latency experience for real-time transmission. Historical frames in the retransmission queue are assigned to low-priority token buckets, using only the remaining bandwidth resources of real-time frames to avoid retransmission traffic crowding out real-time transmission bandwidth. All retransmission frames are equipped with a retransmission flag for easy identification and processing by the server.

[0059] During transmission, the device maintains a retransmission pointer, recording the sequence number of the currently transmitted retransmission frames. When the sequence number of the retransmission pointer catches up with the latest frame sequence number generated by real-time encoding, the retransmission queue is cleared, and the device automatically switches back to normal dual-path parallel transmission mode. It no longer reads retransmission data from the TF card, achieving a seamless switch from retransmission to real-time transmission without user awareness. If a network interruption occurs again during retransmission, the device reverts to pure buffer mode, synchronously recording the sequence numbers of transmitted but unacknowledged frames. The breakpoint is recalculated upon network recovery, preventing duplicate transmissions or data loss.

[0060] S53. Server-side idempotent reception processing. After receiving a retransmitted frame, the server executes idempotent verification logic. For frames with sequence numbers less than the currently acknowledged maximum sequence number, an acknowledgment message is returned directly without being written to disk again. For frames falling within the out-of-order buffer range, it checks if they already exist; if not, they are added to the buffer; otherwise, an acknowledgment is returned directly. For new consecutive sequence number frames, a disk write operation is performed, and the checkpoint status and streaming hash context are updated.

[0061] After each batch of consecutive frames is written to disk, the server synchronously updates the checkpoint record and persists it to disk to ensure that the breakpoint state is not lost after an abnormal server restart. When frames in the out-of-order buffer form a continuous interval, the server advances next_seq in batches and synchronously updates the streaming hash state to ensure the continuity of verification.

[0062] S6, Stream Integrity Verification and Session Termination.

[0063] S61. Streaming Hash Incremental Update Rules. Streaming integrity verification is implemented based on the incrementally updatable SHA-256 algorithm, with the device and server following completely consistent update rules. The entire verification process uses only the pure Opus-encoded payload as input, without any protocol encapsulation headers, padding bytes, or flag fields. The hash context is input frame by frame in ascending order of frame sequence number, and the input order strictly corresponds to the frame timing.

[0064] The intermediate hash state contains three core sets of data: the current values ​​of eight 32-bit hash registers, the total number of bytes processed, and a buffer of remaining message blocks of less than 64 bytes. After each update, the intermediate state can be serialized into fixed-length binary data and stored in the checkpoint persistent storage; during recovery, it can be directly deserialized and loaded to resume calculation from the breakpoint, ensuring byte-level continuity of hash calculations across multiple network outages.

[0065] S62. Session End Trigger and Termination Signaling. When the user triggers the recording stop operation, the device stops audio acquisition and encoding, generates an EOF frame with an end marker, and sends it to the transmission and buffering link. After all frames to be sent have been sent, the device calls the hash termination function, fills in the message length, and performs the final hash calculation to obtain the final complete audio hash value. The hash value is then encapsulated in an END termination signaling message and sent to the server.

[0066] S63. Integrity Verification and Exception Handling. After receiving the EOF frame, the server waits for all consecutive frames to be completed, and then performs a hash termination calculation to obtain the final hash value on the server side. Upon receiving the END signaling, the locally calculated hash value is compared with the device-side hash value carried in the signaling.

[0067] If the two are completely consistent, it is determined that the transmitted audio data is complete, without loss or tampering, and an END_ACK success response is returned to the device. At the same time, the audio file is marked as complete and valid, and access capability is provided to the outside world.

[0068] If the two are inconsistent, a segmented verification and tracing mechanism is initiated. The server divides the data into segments of 1000 frames each, calculates the hash value of each segment, and compares it one by one with the hash value of the corresponding segment on the device to locate the segment range with abnormal data. The abnormal segment sequence number is returned to the device. The device reads the corresponding frame data from the TF card based on the abnormal segment sequence number, retransmits it, and then re-verifies it, without needing to retransmit the entire data.

[0069] S7, cache resource reclamation and exception fallback.

[0070] S71. Normal Session Cache Cleanup. After receiving the END_ACK successful response, the device confirms that the recording session transmission is complete and the data is intact. It then deletes the corresponding session cache file from the TF storage card, releasing storage resources. At the same time, it cleans up resources such as session state, sending window, and hash context in the terminal memory, completing the session termination.

[0071] S72. Abnormal Scenario Caching Backup. If an abnormal termination occurs during recording, such as a power outage or program crash, the device will automatically scan for residual cache files on the TF memory card upon the next startup. Files with corresponding active sessions will be retained and supported for subsequent downloads. Orphan cache files without corresponding active sessions will be retained for 7 days and automatically deleted after expiration to avoid unnecessary storage space occupation.

[0072] This embodiment, through the complete process described above, can achieve low-latency transmission of real-time audio, data preservation during long-term network outages, and full-process integrity verification in scenarios with frequent fluctuations in mobile networks. It is suitable for various evidence preservation scenarios with high requirements for audio reliability, such as field law enforcement, outdoor inspections, and on-site intercoms.

Claims

1. A method for adaptive audio stream transmission and integrity protection based on terminal caching during network outages, implemented using an audio acquisition terminal and a cloud server, characterized in that... Includes the following steps: S1. The audio acquisition terminal encodes the acquired audio data into audio frames with continuously increasing sequence numbers, and synchronously splits them into two parallel processing streams. One stream is uploaded to the cloud server in real time, and the other stream is written to the terminal's local persistent storage medium. S2. During normal transmission, the cloud server confirms the reception status according to the frame sequence number and sends back an acknowledgment message. The audio acquisition terminal maintains the sending sliding window based on the acknowledgment message and dynamically adjusts the retransmission strategy in combination with the network status. S3. Network interruption is identified through a dual mechanism of frame timeout statistics and heartbeat detection. After the network is disconnected, the network transmission link is suspended to keep audio acquisition and local buffer running continuously. S4. After the network is restored, the connection is rebuilt. The audio acquisition terminal initiates a resume request. The cloud server retrieves the breakpoint record that is persistently stored independently of the connection lifecycle to locate the sequence number of the first missing audio frame. S5. The audio acquisition terminal reads the missing frames from the local storage medium of the terminal for retransmission. During the scheduling process, the real-time transmission of newly acquired audio is prioritized. After the retransmission catches up with the real-time frames, the dual-path parallel transmission is seamlessly restored. S6. The terminal and the server synchronously update the incremental hash calculation status frame by frame. The intermediate hash state is persistently saved with the breakpoint record. When the session ends, both ends calculate the final check value respectively. If they match, the audio is determined to be complete. S7. After the normal session transmission is completed, delete the cache file of the corresponding session in the terminal's local storage medium; If the device terminates abnormally, it will scan for residual cache files after restarting and retain the ability to resume transmission for valid sessions.

2. The method for adaptive audio stream transmission and integrity protection based on terminal caching in accordance with claim 1, characterized in that, S1 includes: S11. The audio acquisition terminal establishes an encrypted long connection with the cloud server. The terminal sends a session initiation signaling message, carrying the global file identifier, transmission mode category and audio encoding parameters. The server creates an independent state instance for the current session, initializes the expected received frame sequence number and verification context, and returns a response message carrying the session identifier and the initial receiving window. S12. The terminal collects raw audio data, divides it into blocks of fixed duration, generates audio frames through compression encoding, assigns a continuously increasing globally unique frame sequence number to each frame, and synchronously initializes the streaming hash calculation context. S13. The encoded audio frame is sent to the circular buffer queue and read independently and in parallel by the upload task thread and the cache task thread. The upload task encapsulates the data into a transmission message and sends it to the server in a non-blocking manner. The cache task writes the audio frame to the terminal's local storage medium according to the preset frame storage format. The storage frame is address-aligned according to the maximum space occupied by a single frame, and the storage offset is calculated by multiplying the frame sequence number by the space occupied by a single frame.

3. The method for adaptive audio stream transmission and integrity protection based on terminal caching in accordance with claim 1, characterized in that, S2 includes: S21. After receiving the audio frame, the cloud server processes it according to the frame sequence number and the current receiving status. Duplicate frames are directly returned for confirmation, out-of-order frames are temporarily stored in the out-of-order buffer, and consecutive frames are written to storage and the streaming hash context is updated synchronously. S22. After the cloud server finishes processing the consecutive frames, it returns an acknowledgment message to the terminal carrying the largest sequence number that has been received consecutively. The audio acquisition terminal maintains a sliding window for sending. After receiving the acknowledgment message, it slides the left boundary of the window, releases the storage resources of the confirmed frames, and dynamically adjusts the window size according to network latency and packet loss status. S23. The audio acquisition terminal starts a retransmission timeout timer for each sent frame and dynamically calculates the timeout threshold based on the network round-trip delay sampling value. When a timeout is triggered and the number of retransmissions has not reached the upper limit, backoff retransmission is performed. When multiple consecutive frames trigger timeouts and there is no heartbeat response, the network interruption judgment process is entered.

4. The method for adaptive audio stream transmission and integrity protection based on terminal caching in accordance with claim 1, characterized in that, S3 includes: S31. When a preset number of consecutive audio frames trigger a retransmission timeout and no corresponding acknowledgment message is received, and the periodically sent heartbeat message does not receive a response from the server within a preset time limit, it is determined that the network is interrupted, the current sending window state is frozen, and new audio frames are stopped from being sent to the network. S32. After determining that the network is disconnected, it automatically switches to pure buffer working mode. The audio acquisition, encoding and frame sequence number allocation process continues to run. All new audio frames are written to the terminal's local storage medium. At the same time, it periodically initiates network detection to verify network connectivity. Once the network is detected to be restored, it immediately starts the resume transmission process.

5. The method for adaptive audio stream transmission and integrity protection based on terminal caching in accordance with claim 1, characterized in that, S4 includes: S41. After the network is restored and connectivity verification is successful, the audio acquisition terminal rebuilds the encrypted long connection with the cloud server, sends a resume signaling message, carrying the file identifier of the original session and the maximum frame sequence number generated by the current terminal. S42. The cloud server retrieves the breakpoint record from persistent storage based on the file identifier. This record is saved independently of the original connection's lifecycle. Based on the confirmed consecutive maximum sequence number and the out-of-order frame sequence number bitmap, it traverses and locates the first missing frame sequence number, while loading the intermediate calculation state of the streaming hash. S43. The cloud server encapsulates the sequence number of the first missing frame, the number of frames to be retransmitted, and the list of received out-of-order frame sequence numbers into a resume response message and returns it to the terminal. If there is no corresponding breakpoint record, it returns a reset flag to notify the terminal to start the transmission from the beginning.

6. The method for adaptive audio stream transmission and integrity protection based on terminal caching in accordance with claim 1, characterized in that, In step S4, the cloud server retrieves the persistently stored breakpoint record based on the file identifier. The breakpoint record is saved independently of the original connection's lifecycle. Based on the confirmed consecutive maximum sequence number and the out-of-order frame sequence number bitmap, the server locates the first missing frame sequence number and loads the intermediate calculation state of the streaming hash. The server feeds back the first missing frame sequence number, the number of frames to be retransmitted, and the list of received out-of-order frame sequence numbers to the terminal. If there is no corresponding breakpoint record, the server is notified to start the transmission from the beginning.

7. The method for adaptive audio stream transmission and integrity protection based on terminal caching in accordance with claim 6, characterized in that, The breakpoint records are persistently stored using append-only log writing and periodic snapshots. When the server restarts, the breakpoint state of the session is restored by using snapshots and log replay.

8. The method for adaptive audio stream transmission and integrity protection based on terminal caching in accordance with claim 1, characterized in that, S5 includes: S51. The audio acquisition terminal parses the continuation response message, locates the corresponding audio frame in the local storage medium of the terminal according to the mapping relationship between the frame sequence number and the storage offset, skips the out-of-order frames that have been received by the server, extracts the unreceived frames to form a retransmission queue, and reads the local cached frames using a batch pre-read mechanism, continuously reading a preset number of audio frames each time and storing them in the memory buffer. S52. A bandwidth control mechanism and priority scheduling strategy are adopted to allocate high priority to newly acquired real-time frames and low priority to retransmission frames, which occupy the remaining bandwidth of real-time transmission. When the sequence number of the retransmission frame catches up with the sequence number of the latest real-time generated frame, the system switches back to the normal dual-path parallel transmission mode.

9. The method for adaptive audio stream transmission and integrity protection based on terminal caching in accordance with claim 8, characterized in that, It also includes the cloud server performing idempotency verification on the retransmitted frames. For frames with sequence numbers less than the currently confirmed maximum sequence number, an acknowledgment message is returned directly. For frames falling within the out-of-order buffer range, it is checked whether they already exist. If they do not exist, they are added to the buffer. For new consecutive sequence number frames, disk write operation is performed and the breakpoint record and hash status are updated synchronously. When frames in the out-of-order buffer range form a consecutive range, the receiving sequence number is advanced in batches and the status is updated.

10. The method for adaptive audio stream transmission and integrity protection based on terminal caching according to any one of claims 1-9, characterized in that, S6 includes: S61. The audio acquisition terminal and the cloud server follow the same hash calculation rules. The pure audio encoded payload is used as input, and the hash context is updated frame by frame in ascending order of frame number. The intermediate hash state can be serialized and persistently stored. After the network is restored, it is loaded and the calculation is continued to complete the verification of continuity across multiple network outages. S62. After the terminal stops audio acquisition, it generates a termination frame with an end marker and sends it to the transmission and buffering link. After all frames to be sent have been transmitted, the terminal calculates the final hash check value, encapsulates it into an end signaling message, and sends it to the server. S63. After receiving all consecutive frames, the server calculates the final hash value and compares it with the terminal hash value carried in the end signaling. If the comparison matches, the audio data is determined to be complete and valid. If the comparison does not match, the segmentation verification mechanism is activated. The data is divided into segments according to a fixed number of frames and compared one by one. After locating the abnormal segment, it is retransmitted in a targeted manner.

Citation Information

Patent Citations

  • Uplink frame data backup retransmission method, device and program product

    CN119052259A