noobs 0.0.130 → 0.0.141

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/dist/noobs.node CHANGED
Binary file
package/index.d.ts CHANGED
@@ -147,6 +147,10 @@ export type SceneItemPosition = {
147
147
  y: number; // Y position in pixels
148
148
  scaleX: number; // X scaling factor
149
149
  scaleY: number; // Y scaling factor
150
+ cropLeft: number; // Pixels to crop from the left
151
+ cropRight: number; // Pixels to crop from the right
152
+ cropTop: number; // Pixels to crop from the top
153
+ cropBottom: number; // Pixels to crop from the bottom
150
154
  };
151
155
 
152
156
  export type SourceDimensions = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "noobs",
3
- "version": "0.0.130",
3
+ "version": "0.0.141",
4
4
  "description": "A native Node.js addon with libobs bindings for Warcraft Recorder.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
package/src/main.cpp CHANGED
@@ -554,16 +554,24 @@ Napi::Value ObsGetSourcePos(const Napi::CallbackInfo& info) {
554
554
 
555
555
  std::string name = info[0].As<Napi::String>().Utf8Value();
556
556
 
557
- vec2 pos; vec2 size; vec2 scale;
558
- obs->getSourcePos(name, &pos, &size, &scale);
557
+ vec2 pos; vec2 size; vec2 scale; obs_sceneitem_crop crop;
558
+ obs->getSourcePos(name, &pos, &size, &scale, &crop);
559
559
 
560
560
  Napi::Object result = Napi::Object::New(info.Env());
561
+
561
562
  result.Set("x", Napi::Number::New(info.Env(), pos.x));
562
563
  result.Set("y", Napi::Number::New(info.Env(), pos.y));
564
+
563
565
  result.Set("width", Napi::Number::New(info.Env(), size.x));
564
566
  result.Set("height", Napi::Number::New(info.Env(), size.y));
565
567
  result.Set("scaleX", Napi::Number::New(info.Env(), scale.x));
566
568
  result.Set("scaleY", Napi::Number::New(info.Env(), scale.y));
569
+
570
+ result.Set("cropLeft", Napi::Number::New(info.Env(), crop.left));
571
+ result.Set("cropRight", Napi::Number::New(info.Env(), crop.right));
572
+ result.Set("cropTop", Napi::Number::New(info.Env(), crop.top));
573
+ result.Set("cropBottom", Napi::Number::New(info.Env(), crop.bottom));
574
+
567
575
  return result;
568
576
  }
569
577
 
@@ -593,7 +601,13 @@ Napi::Value ObsSetSourcePos(const Napi::CallbackInfo& info) {
593
601
  float scaleY = position.Get("scaleY").As<Napi::Number>().FloatValue();
594
602
  vec2 scale = { scaleX, scaleY };
595
603
 
596
- obs->setSourcePos(name, &pos, &scale);
604
+ int cropLeft = position.Get("cropLeft").As<Napi::Number>().Int32Value();
605
+ int cropRight = position.Get("cropRight").As<Napi::Number>().Int32Value();
606
+ int cropTop = position.Get("cropTop").As<Napi::Number>().Int32Value();
607
+ int cropBottom = position.Get("cropBottom").As<Napi::Number>().Int32Value();
608
+ obs_sceneitem_crop crop = { cropLeft, cropTop, cropRight, cropBottom }; // Careful with ordering.
609
+
610
+ obs->setSourcePos(name, &pos, &scale, &crop);
597
611
  return info.Env().Undefined();
598
612
  }
599
613
 
@@ -401,11 +401,12 @@ std::string ObsInterface::createSource(std::string name, std::string type) {
401
401
  obs_volmeter_t *volmeter = obs_volmeter_create(OBS_FADER_CUBIC);
402
402
  obs_volmeter_attach_source(volmeter, source);
403
403
 
404
- SignalContext* ctx = new SignalContext{ this, real_name }; // TODO don't leak this.
404
+ SignalContext* ctx = new SignalContext{ this, real_name };
405
405
  obs_volmeter_add_callback(volmeter, volmeter_callback, ctx);
406
406
 
407
407
  // Store the volmeter in the volmeters map.
408
408
  volmeters[real_name] = volmeter;
409
+ volmeter_cb_ctx[real_name] = ctx; // Track this so we can free it later.
409
410
  }
410
411
 
411
412
  if (type == AUDIO_INPUT && force_mono) {
@@ -462,6 +463,15 @@ void ObsInterface::deleteSource(std::string name) {
462
463
  volmeters.erase(name);
463
464
  }
464
465
 
466
+ // Now deal with the callback context.
467
+ auto ctx_it = volmeter_cb_ctx.find(name);
468
+
469
+ if (ctx_it != volmeter_cb_ctx.end()) {
470
+ SignalContext* ctx = ctx_it->second;
471
+ delete ctx;
472
+ volmeter_cb_ctx.erase(ctx_it);
473
+ }
474
+
465
475
  // Now deal with the source itself.
466
476
  auto it = sources.find(name);
467
477
 
@@ -508,7 +518,6 @@ obs_data_t* ObsInterface::getSourceSettings(std::string name) {
508
518
  throw std::runtime_error("Failed to get source settings!");
509
519
  }
510
520
 
511
- // obs_data_release(settings); TODO release after returning to client.
512
521
  return settings;
513
522
  }
514
523
 
@@ -588,14 +597,15 @@ void ObsInterface::disconnect_signal_handlers(obs_output_t *output) {
588
597
 
589
598
  bool draw_source_outline(obs_scene_t *scene, obs_sceneitem_t *item, void *p) {
590
599
  // Get the item position and size
591
- vec2 pos; vec2 scale;
600
+ vec2 pos; vec2 scale; obs_sceneitem_crop crop;
592
601
  obs_sceneitem_get_pos(item, &pos);
593
602
  obs_sceneitem_get_scale(item, &scale);
603
+ obs_sceneitem_get_crop(item, &crop);
594
604
 
595
605
  // Calculate actual size with scaling
596
606
  obs_source_t *src = obs_sceneitem_get_source(item);
597
- float width = obs_source_get_width(src) * scale.x;
598
- float height = obs_source_get_height(src) * scale.y;
607
+ float width = (obs_source_get_width(src) - crop.left - crop.right) * scale.x;
608
+ float height = (obs_source_get_height(src) - crop.top - crop.bottom) * scale.y;
599
609
 
600
610
  if (width <= 0 || height <= 0) {
601
611
  // Don't want to call gs_draw_sprite with zero width or height.
@@ -625,7 +635,7 @@ bool draw_source_outline(obs_scene_t *scene, obs_sceneitem_t *item, void *p) {
625
635
 
626
636
  // Bottom border
627
637
  gs_matrix_push();
628
- gs_matrix_translate3f(pos.x, pos.y + height - 4.0f, 0.0f);
638
+ gs_matrix_translate3f(pos.x, pos.y + height - 4.0f, 0.0f);
629
639
  gs_draw_sprite(nullptr, 0, width, 4.0f);
630
640
  gs_matrix_pop();
631
641
 
@@ -643,7 +653,7 @@ bool draw_source_outline(obs_scene_t *scene, obs_sceneitem_t *item, void *p) {
643
653
 
644
654
  // Dragging point box (25x25 pixels in bottom-right corner)
645
655
  gs_matrix_push();
646
- gs_matrix_translate3f(pos.x + width - 25.0f, pos.y + height - 25.0f, 0.0f);
656
+ gs_matrix_translate3f(pos.x + width - 25.0f, pos.y + height - 25.0f, 0.0f);
647
657
  gs_draw_sprite(nullptr, 0, 25.0f, 25.0f);
648
658
  gs_matrix_pop();
649
659
 
@@ -743,8 +753,8 @@ void ObsInterface::initPreview(HWND parent) {
743
753
 
744
754
  gs_init_data gs_data = {};
745
755
  gs_data.adapter = 0;
746
- gs_data.cx = 1920; // TODO get from video context?
747
- gs_data.cy = 1080; // TODO get from video context?
756
+ gs_data.cx = 1920; // Gets overwritten when we call configurePreview().
757
+ gs_data.cy = 1080; // Gets overwritten when we call configurePreview().
748
758
  gs_data.format = GS_BGRA;
749
759
  gs_data.zsformat = GS_ZS_NONE;
750
760
  gs_data.num_backbuffers = 1;
@@ -787,9 +797,6 @@ void ObsInterface::configurePreview(int x, int y, int width, int height) {
787
797
  return;
788
798
  }
789
799
 
790
- uint32_t w, h;
791
- obs_display_size(display, &w, &h); // Get the display size to match the video context.
792
- blog(LOG_INFO, "Current Display size set to (%d x %d)", w, h);
793
800
  obs_display_resize(display, width, height);
794
801
  obs_display_set_enabled(display, true);
795
802
  }
@@ -897,6 +904,12 @@ ObsInterface::~ObsInterface() {
897
904
  volmeters.erase(kv.first);
898
905
  }
899
906
 
907
+ for (auto& kv : volmeter_cb_ctx) {
908
+ SignalContext* ctx = kv.second;
909
+ delete ctx;
910
+ volmeter_cb_ctx.erase(kv.first);
911
+ }
912
+
900
913
  delete starting_ctx;
901
914
  delete start_ctx;
902
915
  delete stopping_ctx;
@@ -1114,22 +1127,25 @@ std::string ObsInterface::getLastRecording() {
1114
1127
  void ObsInterface::addSourceToScene(std::string name) {
1115
1128
  blog(LOG_INFO, "ObsInterface::addSourceToScene called for source: %s", name.c_str());
1116
1129
 
1130
+ obs_sceneitem_t *item = obs_scene_find_source(scene, name.c_str());
1131
+
1132
+ if (item) {
1133
+ blog(LOG_WARNING, "Source %s already in scene", name.c_str());
1134
+ return;
1135
+ }
1136
+
1117
1137
  auto it = sources.find(name);
1118
1138
 
1119
1139
  if (it == sources.end()) {
1120
1140
  blog(LOG_WARNING, "Source %s not found when adding to scene", name.c_str());
1121
- throw std::runtime_error("Source not found!");
1141
+ return;
1122
1142
  }
1123
1143
 
1124
1144
  obs_source_t* source = it->second;
1125
-
1126
- // TODO refuse to add twice?
1127
- obs_sceneitem_t *item = obs_scene_add(scene, source);
1145
+ item = obs_scene_add(scene, source);
1128
1146
 
1129
1147
  if (!item) {
1130
1148
  blog(LOG_ERROR, "Failed to add source to scene: %s", name.c_str());
1131
- obs_source_release(source);
1132
- throw std::runtime_error("Failed to add source to scene");
1133
1149
  }
1134
1150
 
1135
1151
  blog(LOG_INFO, "ObsInterface::addSourceToScene exited");
@@ -1149,7 +1165,7 @@ void ObsInterface::removeSourceFromScene(std::string name) {
1149
1165
  blog(LOG_INFO, "ObsInterface::removeSourceFromScene exited");
1150
1166
  }
1151
1167
 
1152
- void ObsInterface::getSourcePos(std::string name, vec2* pos, vec2* size, vec2* scale)
1168
+ void ObsInterface::getSourcePos(std::string name, vec2* pos, vec2* size, vec2* scale, obs_sceneitem_crop* crop)
1153
1169
  {
1154
1170
  auto it = sources.find(name);
1155
1171
 
@@ -1174,13 +1190,14 @@ void ObsInterface::getSourcePos(std::string name, vec2* pos, vec2* size, vec2* s
1174
1190
 
1175
1191
  obs_sceneitem_get_pos(item, pos);
1176
1192
  obs_sceneitem_get_scale(item, scale);
1193
+ obs_sceneitem_get_crop(item, crop);
1177
1194
 
1178
1195
  // Pre-scaled sizes.
1179
1196
  size->x = obs_source_get_width(source);
1180
1197
  size->y = obs_source_get_height(source);
1181
1198
  }
1182
1199
 
1183
- void ObsInterface::setSourcePos(std::string name, vec2* pos, vec2* scale) {
1200
+ void ObsInterface::setSourcePos(std::string name, vec2* pos, vec2* scale, obs_sceneitem_crop* crop) {
1184
1201
  obs_sceneitem_t *item = obs_scene_find_source(scene, name.c_str());
1185
1202
 
1186
1203
  if (!item) {
@@ -1190,6 +1207,7 @@ void ObsInterface::setSourcePos(std::string name, vec2* pos, vec2* scale) {
1190
1207
 
1191
1208
  obs_sceneitem_set_pos(item, pos);
1192
1209
  obs_sceneitem_set_scale(item, scale);
1210
+ obs_sceneitem_set_crop(item, crop);
1193
1211
  }
1194
1212
 
1195
1213
  std::vector<std::string> ObsInterface::listAvailableVideoEncoders()
@@ -67,8 +67,8 @@ class ObsInterface {
67
67
 
68
68
  void addSourceToScene(std::string name); // Add source to scene.
69
69
  void removeSourceFromScene(std::string name); // Remove source from scene.
70
- void getSourcePos(std::string name, vec2* pos, vec2* size, vec2* scale); // Size is returned to allow clients to calculate scale.
71
- void setSourcePos(std::string name, vec2* pos, vec2* scale); // Size does not get set here because it's set by the source itself.
70
+ void getSourcePos(std::string name, vec2* pos, vec2* size, vec2* scale, obs_sceneitem_crop* crop); // Size is returned to allow clients to calculate scale.
71
+ void setSourcePos(std::string name, vec2* pos, vec2* scale, obs_sceneitem_crop* crop); // Size does not get set here because it's set by the source itself.
72
72
 
73
73
  void initPreview(HWND parent); // Must call this before showPreview to setup resources.
74
74
  void configurePreview(int x, int y, int width, int height); // Move and resize the preview display.
@@ -85,6 +85,7 @@ class ObsInterface {
85
85
  std::map<std::string, obs_source_t*> sources; // Map of source names to obs_source_t pointers.
86
86
  std::map<std::string, SourceSize> sizes; // Map of source names to their last known size, used for firing callbacks on size changes.
87
87
  std::map<std::string, obs_volmeter_t*> volmeters; // Map of source names to obs_volmeter_t pointers.
88
+ std::map<std::string, SignalContext*> volmeter_cb_ctx; // Map of volmeter callback contexts.
88
89
  std::map<std::string, obs_source_t*> filters; // Map of source names to obs_source_t filter pointers.
89
90
 
90
91
  void sourceCallback(std::string name); // Send callback for source change.