@scrypted/libav 1.0.143 → 1.0.144

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.ts CHANGED
@@ -51,8 +51,8 @@ export interface AVPacket {
51
51
  readonly streamIndex: number;
52
52
  flags: number;
53
53
  readonly size: number;
54
- readonly pts: number;
55
- readonly dts: number;
54
+ pts: number;
55
+ dts: number;
56
56
  readonly duration: number;
57
57
  [Symbol.dispose](): void;
58
58
  getData(): Buffer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scrypted/libav",
3
- "version": "1.0.143",
3
+ "version": "1.0.144",
4
4
  "dependencies": {
5
5
  "detect-libc": "^2.0.3",
6
6
  "follow-redirects": "^1.15.9",
@@ -167,6 +167,7 @@ public:
167
167
  ReceivePacketWorker(napi_env env, napi_deferred deferred, AVCodecContext *codecContext)
168
168
  : Napi::AsyncWorker(env), deferred(deferred), codecContext(codecContext)
169
169
  {
170
+ result = nullptr;
170
171
  }
171
172
 
172
173
  void Execute() override
@@ -599,6 +599,7 @@ Napi::Value AVFormatContextObject::Create(const Napi::CallbackInfo &info)
599
599
  if (formatName == "rtp")
600
600
  {
601
601
  int MAX_RTP_PACKET_SIZE = 65536;
602
+ fmt_ctx_->packet_size = MAX_RTP_PACKET_SIZE;
602
603
  RTPMuxContext *rtp_ctx = (RTPMuxContext *)fmt_ctx_->priv_data;
603
604
  rtp_ctx->max_payload_size = MAX_RTP_PACKET_SIZE - 12;
604
605
  rtp_ctx->buf = (uint8_t *)av_malloc(MAX_RTP_PACKET_SIZE);
@@ -738,7 +739,7 @@ Napi::Value AVFormatContextObject::NewStream(const Napi::CallbackInfo &info)
738
739
  Napi::Error::New(env, "Format context is null").ThrowAsJavaScriptException();
739
740
  return env.Undefined();
740
741
  }
741
- if (streamIndex < 0 || streamIndex >= formatContext->nb_streams)
742
+ if (streamIndex >= formatContext->nb_streams)
742
743
  {
743
744
  Napi::Error::New(env, "Invalid stream index").ThrowAsJavaScriptException();
744
745
  return env.Undefined();
@@ -770,17 +771,14 @@ Napi::Value AVFormatContextObject::NewStream(const Napi::CallbackInfo &info)
770
771
  return env.Undefined();
771
772
  }
772
773
 
773
- // gpt says supposed to send this but sends empty packet which crashes.
774
- // sps/pps seem to be sent correctly though.
775
- // may be an issue on mp4 where there's a moov header?
776
- // int ret;
777
- // if ((ret = avformat_write_header(fmt_ctx_, NULL)) < 0)
778
- // {
779
- // avformat_free_context(fmt_ctx_);
780
- // fmt_ctx_ = nullptr;
781
- // Napi::Error::New(env, AVErrorString(ret)).ThrowAsJavaScriptException();
782
- // return env.Undefined();
783
- // }
774
+ int ret;
775
+ if ((ret = avformat_write_header(fmt_ctx_, NULL)) < 0)
776
+ {
777
+ avformat_free_context(fmt_ctx_);
778
+ fmt_ctx_ = nullptr;
779
+ Napi::Error::New(env, AVErrorString(ret)).ThrowAsJavaScriptException();
780
+ return env.Undefined();
781
+ }
784
782
 
785
783
  return Napi::Number::New(env, stream->index);
786
784
  }
package/src/index.ts CHANGED
@@ -149,8 +149,8 @@ export interface AVPacket {
149
149
  readonly streamIndex: number;
150
150
  flags: number;
151
151
  readonly size: number;
152
- readonly pts: number;
153
- readonly dts: number;
152
+ pts: number;
153
+ dts: number;
154
154
  readonly duration: number;
155
155
 
156
156
  [Symbol.dispose](): void;
package/src/packet.cpp CHANGED
@@ -24,8 +24,8 @@ Napi::Object AVPacketObject::Init(Napi::Env env, Napi::Object exports)
24
24
 
25
25
  Napi::Function func = DefineClass(env, "AVPacketObject", {
26
26
  AVPacketObject::InstanceAccessor("flags", &AVPacketObject::GetFlags, &AVPacketObject::SetFlags),
27
- AVPacketObject::InstanceAccessor("pts", &AVPacketObject::GetPTS, nullptr),
28
- AVPacketObject::InstanceAccessor("dts", &AVPacketObject::GetDTS, nullptr),
27
+ AVPacketObject::InstanceAccessor("pts", &AVPacketObject::GetPTS, &AVPacketObject::SetPTS),
28
+ AVPacketObject::InstanceAccessor("dts", &AVPacketObject::GetDTS, &AVPacketObject::SetDTS),
29
29
  AVPacketObject::InstanceAccessor("duration", &AVPacketObject::GetDuration, nullptr),
30
30
  AVPacketObject::InstanceAccessor("size", &AVPacketObject::GetSize, nullptr),
31
31
  AVPacketObject::InstanceAccessor("streamIndex", &AVPacketObject::GetStreamIndex, nullptr),
@@ -119,11 +119,42 @@ Napi::Value AVPacketObject::GetPTS(const Napi::CallbackInfo &info)
119
119
  return Napi::Number::New(info.Env(), packet ? packet->pts : 0);
120
120
  }
121
121
 
122
+ void AVPacketObject::SetPTS(const Napi::CallbackInfo &info, const Napi::Value &value)
123
+ {
124
+ if (!packet)
125
+ {
126
+ return;
127
+ }
128
+
129
+ if (!value.IsNumber())
130
+ {
131
+ Napi::TypeError::New(info.Env(), "Number expected for pts").ThrowAsJavaScriptException();
132
+ return;
133
+ }
134
+
135
+ packet->pts = value.As<Napi::Number>().Int64Value();
136
+ }
137
+
122
138
  Napi::Value AVPacketObject::GetDTS(const Napi::CallbackInfo &info)
123
139
  {
124
140
  return Napi::Number::New(info.Env(), packet ? packet->dts : 0);
125
141
  }
126
142
 
143
+ void AVPacketObject::SetDTS(const Napi::CallbackInfo &info, const Napi::Value &value)
144
+ {
145
+ if (!packet)
146
+ {
147
+ return;
148
+ }
149
+
150
+ if (!value.IsNumber())
151
+ {
152
+ Napi::TypeError::New(info.Env(), "Number expected for dts").ThrowAsJavaScriptException();
153
+ return;
154
+ }
155
+
156
+ packet->dts = value.As<Napi::Number>().Int64Value();
157
+ }
127
158
  Napi::Value AVPacketObject::GetDuration(const Napi::CallbackInfo &info)
128
159
  {
129
160
  return Napi::Number::New(info.Env(), packet ? packet->duration : 0);
package/src/packet.h CHANGED
@@ -30,7 +30,9 @@ public:
30
30
  Napi::Value GetFlags(const Napi::CallbackInfo &info);
31
31
  void SetFlags(const Napi::CallbackInfo &info, const Napi::Value &value);
32
32
  Napi::Value GetPTS(const Napi::CallbackInfo &info);
33
+ void SetPTS(const Napi::CallbackInfo &info, const Napi::Value &value);
33
34
  Napi::Value GetDTS(const Napi::CallbackInfo &info);
35
+ void SetDTS(const Napi::CallbackInfo &info, const Napi::Value &value);
34
36
  Napi::Value GetDuration(const Napi::CallbackInfo &info);
35
37
  Napi::Value GetSize(const Napi::CallbackInfo &info);
36
38
  Napi::Value GetData(const Napi::CallbackInfo &info);