Example #1
0
/**
 * @brief The application main entry point
 * @param argc Command line argument count
 * @param argv Command line argument list
 * @return 0 if the application works well.
 */
int main(int argc, char *argv[])
{
	QCoreApplication a(argc, argv);

	for(int i = 0; i < argc; i++)
		PHDEBUG << argv[i];
	PHDEBUG << "\n\n";

	int apv = 1920;
	ltcsnd_sample_t sound[BUFFER_SIZE];
	size_t n;
	long int total;
	FILE* f;
	char* filename;
	LTCDecoder *decoder;
	LTCFrameExt frame;

	// fIXME
	if (argc > 1) {
		filename = argv[1];
		if (argc > 2) {
			sscanf(argv[2], "%i", &apv);
		}
	}
	else {
		printf("Usage: %s <filename> [audio-frames-per-video-frame]\n", argv[0]);
		return -1;
	}
	f = fopen(filename, "r");
	if (!f) {
		fprintf(stderr, "error opening '%s'\n", filename);
		return -1;
	}
	fprintf(stderr, "* reading from: %s\n", filename);
	total = 0;
	decoder = ltc_decoder_create(apv, 3840);

	do {
		//PHDEBUG << "in da do";
		n = fread(sound, sizeof(ltcsnd_sample_t), BUFFER_SIZE, f);

		//PHDEBUG << n;
		ltc_decoder_write(decoder, sound, n, total);
		//PHDEBUG << "2";

		while (ltc_decoder_read(decoder, &frame)) {
			SMPTETimecode stime;
			ltc_frame_to_time(&stime, &frame.ltc, 1);
			//PHDEBUG << stime.years + 1900 << stime.months << stime.days; // << stime.timezone;
			PHDEBUG << stime.hours << stime.mins << stime.secs << ":" << stime.frame << "\toffStart " << frame.off_start << "\toffEnd" << frame.off_end;
		}
		total += n;
		//PHDEBUG << n;
	}
	while (n);
	fclose(f);
	ltc_decoder_free(decoder);

	return 0;
}
Example #2
0
void ltc_encoder_get_timecode(LTCEncoder *e, SMPTETimecode *t) {
	ltc_frame_to_time(t, &e->f, e->flags);
}
Example #3
0
LtcClock::LtcClock(bool masterClock, const string& deviceName)
{
    registerAttributes();

    _listener = unique_ptr<Listener>(new Listener());
    _listener->setParameters(1, 0, Listener::SAMPLE_FMT_U8, deviceName);
    if (!_listener)
    {
        _listener.reset();
        return;
    }

    _masterClock = masterClock;
    _continue = true;

    Log::get() << Log::MESSAGE << "LtcClock::" << __FUNCTION__ << " - Input clock enabled" << Log::endl;

    _ltcThread = thread([&]() {
        LTCDecoder* ltcDecoder = ltc_decoder_create(1920, 32);
        LTCFrameExt ltcFrame;

        vector<uint8_t> inputBuffer(256);
        long int total = 0;

        while (_continue)
        {
            if (!_listener->readFromQueue(inputBuffer))
            {
                this_thread::sleep_for(chrono::milliseconds(5));
                continue;
            }

            // Check all values to check whether the clock is paused or not
            bool paused = true;
            for (auto& v : inputBuffer)
            {
                if (v < 126 || v > 129) // This is for noise handling. There is not enough room for a clock in between.
                {
                    paused = false;
                    break;
                }
            }

            _clock.paused = paused;

            ltc_decoder_write(ltcDecoder, (ltcsnd_sample_t*)inputBuffer.data(), inputBuffer.size(), total);
            total += inputBuffer.size();

            while (ltc_decoder_read(ltcDecoder, &ltcFrame))
            {
                _ready = true;

                SMPTETimecode stime;
                ltc_frame_to_time(&stime, &ltcFrame.ltc, LTC_TC_CLOCK);

                Clock clock;
                clock.years = stime.years;
                clock.months = stime.months;
                clock.days = stime.days;
                clock.hours = stime.hours;
                clock.mins = stime.mins;
                clock.secs = stime.secs;

                // This updates the maximum frames per second, to be able to handle any framerate
                if (stime.frame == 0)
                {
                    // Only accept some specific values
                    if (_previousFrame == 24 || _previousFrame == 25 || _previousFrame == 30 || _previousFrame == 60)
                    {
                        // Small trick to handle errors
                        if (_framerateChanged)
                        {
                            _maximumFramePerSec = _previousFrame + 1;
                            _framerateChanged = false;
                        }
                        else
                        {
                            _framerateChanged = true;
                        }
                    }
                }

                _previousFrame = stime.frame;
                clock.frame = stime.frame * 120 / _maximumFramePerSec;

                _clock = clock;
            }

            if (_masterClock)
            {
                Values v;
                getClock(v);
                Timer::get().setMasterClock(v);
            }
        }

        ltc_decoder_free(ltcDecoder);
    });
}