<commit_before>/*
 * Copyright 2015 The SageTV Authors. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include <arpa/inet.h>
#include <errno.h>
#include <fcntl.h>
#include <features.h>
#include <getopt.h>
#include <inttypes.h>
#include <libavc1394/avc1394.h>
#include <libiec61883/iec61883.h>
#include <libraw1394/csr.h>
#include <libraw1394/raw1394.h>
#include <linux/types.h>
#include <math.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/errno.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/timeb.h>
#include <sys/types.h>
#include <sys/types.h>
#include <sys/un.h>
#include <time.h>
#include <unistd.h>

#include "sage_EncodingException.h"
#include "sage_FirewireCaptureDevice.h"

#define BUFFERSIZE 188 * 16

static void sysOutPrint(JNIEnv *env, const char *cstr, ...) {
  jthrowable oldExcept = (*env)->ExceptionOccurred(env);
  if (oldExcept) (*env)->ExceptionClear(env);
  va_list args;
  va_start(args, cstr);
  char buf[1024];
  vsprintf(buf, cstr, args);
  va_end(args);
  jstring jstr = (*env)->NewStringUTF(env, buf);
  jclass cls = (jclass)(*env)->NewGlobalRef(
      env, (*env)->FindClass(env, "java/lang/System"));
  jfieldID outField =
      (*env)->GetStaticFieldID(env, cls, "out", "Ljava/io/PrintStream;");
  jmethodID printMeth =
      (*env)->GetMethodID(env, (*env)->FindClass(env, "java/io/PrintStream"),
                          "print", "(Ljava/lang/String;)V");
  jobject outObj = (*env)->GetStaticObjectField(env, cls, outField);
  (*env)->CallVoidMethod(env, outObj, printMeth, jstr);
  (*env)->DeleteLocalRef(env, jstr);
  if (oldExcept) (*env)->Throw(env, oldExcept);
}

typedef struct FirewireCaptureDev {
  FILE *output_file;  // file to write the captured data to
  size_t circFileSize;
  char devName[256];
  unsigned char buf[BUFFERSIZE];
  size_t circWritePos;
  raw1394handle_t handle;
  octlet_t guid;
  int port;
  int node;
  int oplug;
  int iplug;
  int bandwidth;
  int channel;
  octlet_t datalen;
  iec61883_mpeg2_t mpeg;
} FirewireCaptureDev;<commit_msg>Further cleanup of firewire capture code<commit_after>/*
 * Copyright 2015 The SageTV Authors. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include <arpa/inet.h>
#include <libavc1394/avc1394.h>
#include <libiec61883/iec61883.h>
#include <libraw1394/csr.h>
#include <libraw1394/raw1394.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/errno.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>

#include "sage_EncodingException.h"
#include "sage_FirewireCaptureDevice.h"

static void sysOutPrint(JNIEnv *env, const char *cstr, ...) {
  jthrowable oldExcept = (*env)->ExceptionOccurred(env);
  if (oldExcept) (*env)->ExceptionClear(env);
  va_list args;
  va_start(args, cstr);
  char buf[1024];
  vsprintf(buf, cstr, args);
  va_end(args);
  jstring jstr = (*env)->NewStringUTF(env, buf);
  jclass cls = (jclass)(*env)->NewGlobalRef(
      env, (*env)->FindClass(env, "java/lang/System"));
  jfieldID outField =
      (*env)->GetStaticFieldID(env, cls, "out", "Ljava/io/PrintStream;");
  jmethodID printMeth =
      (*env)->GetMethodID(env, (*env)->FindClass(env, "java/io/PrintStream"),
                          "print", "(Ljava/lang/String;)V");
  jobject outObj = (*env)->GetStaticObjectField(env, cls, outField);
  (*env)->CallVoidMethod(env, outObj, printMeth, jstr);
  (*env)->DeleteLocalRef(env, jstr);
  if (oldExcept) (*env)->Throw(env, oldExcept);
}

typedef struct FirewireCaptureDev {
  FILE *output_file;  // file to write the captured data to
  size_t circFileSize;
  char devName[256];
  size_t circWritePos;
  raw1394handle_t handle;
  octlet_t guid;
  int port;
  int node;
  int oplug;
  int iplug;
  int bandwidth;
  int channel;
  octlet_t datalen;
  iec61883_mpeg2_t mpeg;
} FirewireCaptureDev;
{'fraction_non_alphanumeric': 0.1385456755114442, 'fraction_numerical': 0.023293498075754506, 'mean_word_length': 4.38495092693566, 'pattern_counts': {'":': 0, '<': 42, '<?xml version=': 0, '>': 66, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4225758', 'n_tokens_mistral': 1798, 'n_tokens_neox': 1716, 'n_words': 471}