~ubuntu-branches/ubuntu/wily/libffado/wily

« back to all changes in this revision

Viewing changes to src/libieee1394/ieee1394service.cpp

  • Committer: Package Import Robot
  • Author(s): Artem Popov
  • Date: 2013-01-26 14:55:38 UTC
  • mfrom: (8.1.11 experimental)
  • Revision ID: package-import@ubuntu.com-20130126145538-4we9vsu1ra1d7mgh
Tags: 2.1.0+svn2240-1ubuntu1
* Merge with Debian (LP: #1105818); remaining changes:
  - Build using dh_python2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * Copyright (C) 2005-2008 by Daniel Wagner
3
3
 * Copyright (C) 2005-2008 by Pieter Palmers
 
4
 * Copyright (C) 2012 by Jonathan Woithe
4
5
 *
5
6
 * This file is part of FFADO
6
7
 * FFADO = Free Firewire (pro-)audio drivers for linux
47
48
#include <iostream>
48
49
#include <iomanip>
49
50
 
 
51
// Permit linking against older libraw1394 which didn't include this
 
52
// function.
 
53
#ifdef __GNUC__
 
54
  #ifdef __APPLE__
 
55
  #define WEAK_ATTRIBUTE weak_import
 
56
  #else
 
57
  #define WEAK_ATTRIBUTE __weak__
 
58
  #endif
 
59
  int raw1394_read_cycle_timer_and_clock(raw1394handle_t handle,
 
60
      u_int32_t *cycle_timer, u_int64_t *local_time, clockid_t clk_id)
 
61
      __attribute__((WEAK_ATTRIBUTE));
 
62
#endif
 
63
 
50
64
using namespace std;
51
65
 
52
66
IMPL_DEBUG_MODULE( Ieee1394Service, Ieee1394Service, DEBUG_LEVEL_NORMAL );
317
331
    int err;
318
332
    uint32_t cycle_timer;
319
333
    uint64_t local_time;
 
334
    m_have_read_ctr_and_clock = false;
320
335
    err = raw1394_read_cycle_timer(m_util_handle, &cycle_timer, &local_time);
321
336
    if(err) {
322
337
        debugOutput(DEBUG_LEVEL_VERBOSE, "raw1394_read_cycle_timer failed.\n");
329
344
        debugWarning("==================================================================\n");
330
345
        m_have_new_ctr_read = false;
331
346
    } else {
332
 
        debugOutput(DEBUG_LEVEL_VERBOSE, "This system supports the raw1394_read_cycle_timer call, using it.\n");
333
347
        m_have_new_ctr_read = true;
 
348
 
 
349
        // Only if raw1394_read_cycle_timer() is present is it worth even
 
350
        // considering the option that raw1394_read_cycle_timer_and_clock()
 
351
        // might be available.
 
352
        if (raw1394_read_cycle_timer_and_clock != NULL) {
 
353
            err = raw1394_read_cycle_timer_and_clock(m_util_handle, &cycle_timer, &local_time, CLOCK_MONOTONIC);
 
354
            if (!err && Util::SystemTimeSource::setSource(CLOCK_MONOTONIC)==true)
 
355
                m_have_read_ctr_and_clock = true;
 
356
        }
 
357
 
 
358
        if (m_have_read_ctr_and_clock) {
 
359
            debugOutput(DEBUG_LEVEL_VERBOSE, "This system supports the raw1394_read_cycle_timer_and_clock call and the\n");
 
360
            debugOutput(DEBUG_LEVEL_VERBOSE, "CLOCK_MONOTONIC clock source; using them.\n");
 
361
        } else {
 
362
            debugOutput(DEBUG_LEVEL_VERBOSE, "This system supports the raw1394_read_cycle_timer call, using it.\n");
 
363
            debugOutput(DEBUG_LEVEL_NORMAL, "The raw1394_read_cycle_timer_and_clock call and/or the CLOCK_MONOTONIC\n");
 
364
            debugOutput(DEBUG_LEVEL_NORMAL, "clock source is not available.\n");
 
365
            debugOutput(DEBUG_LEVEL_NORMAL, "Fallback to raw1394_read_cycle_timer.\n");
 
366
            debugOutput(DEBUG_LEVEL_NORMAL, "FFADO may be susceptible to NTP-induced clock discontinuities.\n");
 
367
            debugOutput(DEBUG_LEVEL_NORMAL, "If this is an issue, upgrade libraw1394 to version 2.1.0 or later and/or\n");
 
368
            debugOutput(DEBUG_LEVEL_NORMAL, "kernel 2.6.36 or later.\n");
 
369
        }
334
370
    }
335
371
 
336
372
    // obtain port name
373
409
    debugOutput(DEBUG_LEVEL_VERBOSE, "Minimum SPLIT_TIMEOUT: %d. Current: %d\n", split_timeout, timeout);
374
410
    if (timeout < split_timeout) {
375
411
        if(!setSplitTimeoutUsecs(getLocalNodeId(), split_timeout+124)) {
376
 
            debugWarning("Could not set SPLIT_TIMEOUT to min requested (%d)\n", split_timeout);
 
412
            debugOutput(DEBUG_LEVEL_VERBOSE, "Could not set SPLIT_TIMEOUT to min requested (%d)\n", split_timeout);
377
413
        }
378
414
        timeout = getSplitTimeoutUsecs(getLocalNodeId());
379
415
        if (timeout < split_timeout) {
380
 
            debugWarning("Set SPLIT_TIMEOUT to min requested (%d) did not succeed\n", split_timeout);
 
416
            debugOutput(DEBUG_LEVEL_VERBOSE, "Set SPLIT_TIMEOUT to min requested (%d) did not succeed\n", split_timeout);
381
417
        }
382
418
    }
383
419
 
503
539
bool
504
540
Ieee1394Service::readCycleTimerReg(uint32_t *cycle_timer, uint64_t *local_time)
505
541
{
 
542
    if (m_have_read_ctr_and_clock) {
 
543
        int err;
 
544
        err = raw1394_read_cycle_timer_and_clock(m_util_handle, cycle_timer, local_time, 
 
545
                  Util::SystemTimeSource::getSource());
 
546
        if(err) {
 
547
            debugWarning("raw1394_read_cycle_timer_and_clock error: %s\n", strerror(errno));
 
548
            return false;
 
549
        }
 
550
        return true;
 
551
    } else
506
552
    if(m_have_new_ctr_read) {
507
553
        int err;
508
554
        err = raw1394_read_cycle_timer(m_util_handle, cycle_timer, local_time);
509
555
        if(err) {
510
 
            debugWarning("raw1394_read_cycle_timer: %s\n", strerror(err));
 
556
            debugWarning("raw1394_read_cycle_timer error: %s\n", strerror(errno));
511
557
            return false;
512
558
        }
513
559
        return true;