Skip to content

Commit

Permalink
Merge DataStreamServer from upstream.
Browse files Browse the repository at this point in the history
  • Loading branch information
Koushik Dutta authored and Koushik Dutta committed Jun 28, 2022
1 parent 7eab49d commit 4b1cc68
Show file tree
Hide file tree
Showing 3 changed files with 899 additions and 802 deletions.
6 changes: 3 additions & 3 deletions src/accessories/gstreamer-audioProducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
AudioBitrate,
AudioSamplerate,
AudioCodecTypes,
DataSendCloseReason,
HDSProtocolSpecificErrorReason,
ErrorHandler,
FrameHandler,
SiriAudioStreamProducer, AudioCodecConfiguration
Expand Down Expand Up @@ -122,7 +122,7 @@ export class GStreamerAudioProducer implements SiriAudioStreamProducer {
this.process.on("error", error => {
if (this.running) {
debug("Failed to spawn gstreamer process: " + error.message);
this.errorHandler(DataSendCloseReason.CANCELLED);
this.errorHandler(HDSProtocolSpecificErrorReason.CANCELLED);
} else {
debug("Failed to kill gstreamer process: " + error.message);
}
Expand Down Expand Up @@ -154,7 +154,7 @@ export class GStreamerAudioProducer implements SiriAudioStreamProducer {
this.process.on("exit", (code, signal) => {
if (signal !== "SIGTERM") { // if we receive SIGTERM, process exited gracefully (we stopped it)
debug("GStreamer process unexpectedly exited with code %d (signal: %s)", code, signal);
this.errorHandler(DataSendCloseReason.UNEXPECTED_FAILURE);
this.errorHandler(HDSProtocolSpecificErrorReason.UNEXPECTED_FAILURE);
}
});
}
Expand Down
21 changes: 11 additions & 10 deletions src/lib/controller/RemoteController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
CharacteristicSetCallback
} from "../Characteristic";
import {
DataSendCloseReason,
HDSProtocolSpecificErrorReason,
DataStreamConnection,
DataStreamConnectionEvent,
DataStreamManagement,
Expand Down Expand Up @@ -250,7 +250,7 @@ type AudioFramePacket = {


export type FrameHandler = (frame: AudioFrame) => void;
export type ErrorHandler = (error: DataSendCloseReason) => void;
export type ErrorHandler = (error: HDSProtocolSpecificErrorReason) => void;

export interface SiriAudioStreamProducer {

Expand Down Expand Up @@ -1050,7 +1050,7 @@ export class RemoteController extends EventEmitter implements SerializableContro

private handleDataSendCloseEvent(message: Record<any, any>): void { // controller indicates he can't handle audio request currently
const streamId = message["streamId"];
const reason = message["reason"] as DataSendCloseReason;
const reason = message["reason"] as HDSProtocolSpecificErrorReason;

if (this.activeAudioSession && this.activeAudioSession.streamId === streamId) {
this.activeAudioSession.handleDataSendCloseEvent(reason);
Expand Down Expand Up @@ -1406,7 +1406,7 @@ export class SiriAudioSession extends EventEmitter {
this.streamId = message["streamId"];

if (!this.producerRunning) { // audio producer errored in the meantime
this.sendDataSendCloseEvent(DataSendCloseReason.CANCELLED);
this.sendDataSendCloseEvent(HDSProtocolSpecificErrorReason.CANCELLED);
} else {
debug("Successfully setup siri audio stream with streamId %d", this.streamId);
}
Expand Down Expand Up @@ -1450,7 +1450,7 @@ export class SiriAudioSession extends EventEmitter {
this.producerTimer = setTimeout(() => { // producer has 3s to start producing audio frames
debug("Didn't receive any frames from audio producer for stream with streamId %s. Canceling the stream now.", this.streamId);
this.producerTimer = undefined;
this.handleProducerError(DataSendCloseReason.CANCELLED);
this.handleProducerError(HDSProtocolSpecificErrorReason.CANCELLED);
}, 3000);
this.producerTimer.unref();
}
Expand Down Expand Up @@ -1518,7 +1518,7 @@ export class SiriAudioSession extends EventEmitter {
}
}

private handleProducerError(error: DataSendCloseReason): void { // called from audio producer
private handleProducerError(error: HDSProtocolSpecificErrorReason): void { // called from audio producer
if (this.state >= SiriAudioSessionState.CLOSING) {
return;
}
Expand All @@ -1534,19 +1534,20 @@ export class SiriAudioSession extends EventEmitter {

debug("Received acknowledgment for siri audio stream with streamId %s, closing it now", this.streamId);

this.sendDataSendCloseEvent(DataSendCloseReason.NORMAL);
this.sendDataSendCloseEvent(HDSProtocolSpecificErrorReason.NORMAL);
}

handleDataSendCloseEvent(reason: DataSendCloseReason): void { // controller indicates he can't handle audio request currently
debug("Received close event from controller with reason %s for stream with streamId %s", DataSendCloseReason[reason], this.streamId);
handleDataSendCloseEvent(reason: HDSProtocolSpecificErrorReason): void { // controller indicates he can't handle audio request currently
// @ts-expect-error: forceConsistentCasingInFileNames compiler option
debug("Received close event from controller with reason %s for stream with streamId %s", HDSProtocolSpecificErrorReason[reason], this.streamId);
if (this.state <= SiriAudioSessionState.SENDING) {
this.stopAudioProducer();
}

this.closed();
}

private sendDataSendCloseEvent(reason: DataSendCloseReason): void {
private sendDataSendCloseEvent(reason: HDSProtocolSpecificErrorReason): void {
assert(this.state >= SiriAudioSessionState.SENDING, "state was less than SENDING");
assert(this.state <= SiriAudioSessionState.CLOSING, "state was higher than CLOSING");

Expand Down
Loading

0 comments on commit 4b1cc68

Please sign in to comment.