Exemplo n.º 1
0
        internal override void HandleEvent(NikonObject obj, eNkMAIDEvent currentEvent, IntPtr data)
        {
            switch (currentEvent)
            {
            case eNkMAIDEvent.kNkMAIDEvent_AddChild:
            case eNkMAIDEvent.kNkMAIDEvent_AddChildInCard:
                HandleAddChild(data);
                break;

            case eNkMAIDEvent.kNkMAIDEvent_AddPreviewImage:
                HandleAddPreviewImage(data);
                break;

            case eNkMAIDEvent.kNkMAIDEvent_CaptureComplete:
                Scheduler.Callback(new CaptureCompleteDelegate(OnCaptureComplete), this, (int)data);
                break;

            case eNkMAIDEvent.kNkMAIDEvent_CapChange:
                Scheduler.Callback(new CapabilityChangedDelegate(OnCapabilityChanged), this, (eNkMAIDCapability)data);
                break;

            case eNkMAIDEvent.kNkMAIDEvent_CapChangeValueOnly:
                Scheduler.Callback(new CapabilityChangedDelegate(OnCapabilityValueChanged), this, (eNkMAIDCapability)data);
                break;

            case eNkMAIDEvent.kNkMAIDEvent_RecordingInterrupted:
                Scheduler.Callback(new VideoRecordingInterruptedDelegate(OnVideoRecordingInterrupted), this, (int)data);
                break;

            default:
                Debug.Print("Unhandled event: " + currentEvent + " (" + data.ToString() + ")");
                break;
            }
        }
Exemplo n.º 2
0
        void data_DataFile(NikonObject sender, NkMAIDFileInfo fileInfo, IntPtr data)
        {
            if (fileInfo.ulStart == 0)
            {
                Debug.Assert(_currentImage == null);

                int            size   = (int)fileInfo.ulTotalLength;
                NikonImageType type   = (NikonImageType)(_currentItemId >> 27);
                int            number = (int)((_currentItemId << 8) >> 8);
                bool           isFragmentOfRawPlusJpeg = (_currentItemId & (1 << 26)) != 0;

                _currentImage = new NikonImage(size, type, number, isFragmentOfRawPlusJpeg);
            }

            Debug.Assert(_currentImage != null);

            int offset = (int)fileInfo.ulStart;
            int length = (int)fileInfo.ulLength;

            _currentImage.CopyFrom(data, offset, length);

            bool complete = (fileInfo.ulTotalLength == fileInfo.ulStart + fileInfo.ulLength);

            if (complete)
            {
                NikonImage image = _currentImage;
                _currentImage = null;

                Scheduler.Callback(new ImageReadyDelegate(OnImageReady), this, image);
            }
        }
Exemplo n.º 3
0
        internal void InitializeObject(NikonObject obj)
        {
            _object = obj;
            _object.Open();
            _object.Event += _object_Event;

            RefreshCaps();
        }
Exemplo n.º 4
0
 void data_Progress(NikonObject sender,
                    eNkMAIDCommand ulCommand,
                    UInt32 ulParam,
                    IntPtr refComplete,
                    UInt32 ulDone,
                    UInt32 ulTotal)
 {
     Scheduler.Callback(new ProgressDelegate(OnProgress), this, (eNkMAIDDataObjType)sender.Id, (int)ulDone, (int)ulTotal);
 }
Exemplo n.º 5
0
        void _object_Event(NikonObject sender, IntPtr refClient, eNkMAIDEvent ulEvent, IntPtr data)
        {
            switch (ulEvent)
            {
            case eNkMAIDEvent.kNkMAIDEvent_CapChange:
                RefreshCaps();
                break;
            }

            HandleEvent(sender, ulEvent, data);
        }
Exemplo n.º 6
0
        internal NikonDevice(NikonMd3 md3, NikonScheduler scheduler, NikonObject parent, NikonModuleType moduleType, uint deviceId)
            : base(md3, scheduler)
        {
            Debug.Assert(Scheduler.WorkerThreadId == Thread.CurrentThread.ManagedThreadId);

            ModuleType = moduleType;

            NikonObject source = new NikonObject(md3, parent, deviceId);

            InitializeObject(source);
        }
Exemplo n.º 7
0
        internal override void HandleEvent(NikonObject obj, eNkMAIDEvent currentEvent, IntPtr data)
        {
            switch (currentEvent)
            {
            case eNkMAIDEvent.kNkMAIDEvent_AddChild:
                HandleAddChild(data);
                break;

            case eNkMAIDEvent.kNkMAIDEvent_RemoveChild:
                HandleRemoveChild(data);
                break;
            }
        }
Exemplo n.º 8
0
        void DataItemAcquire(NikonObject data)
        {
            // Listen for progress
            data.Progress += data_Progress;

            // Listen for data
            data.DataFile  += data_DataFile;
            data.DataImage += data_DataImage;
            data.DataSound += data_DataSound;

            // Try to acquire the data object
            try
            {
                data.CapStart(
                    eNkMAIDCapability.kNkMAIDCapability_Acquire,
                    eNkMAIDDataType.kNkMAIDDataType_Null,
                    IntPtr.Zero);
            }
            catch (NikonException ex)
            {
                // Is this a 'NotSupported' exception?
                bool isNotSupported = (ex.ErrorCode == eNkMAIDResult.kNkMAIDResult_NotSupported);

                // Is this a 'Thumbnail' data object?
                bool isThumbnail = (data.Id == (uint)eNkMAIDDataObjType.kNkMAIDDataObjType_Thumbnail);

                // According to the documentation, acquiring a thumbnail data object
                // sometimes produces a NotSupported error. Apparently this is expected,
                // so we ignore this specific case here.
                bool isAllowed = isNotSupported && isThumbnail;

                if (isAllowed)
                {
                    Debug.Print("Failed to retrieve thumbnail image");
                }
                else
                {
                    // If this is some other case, rethrow the exception
                    throw;
                }
            }
            finally
            {
                // Unhook data object events
                data.Progress  -= data_Progress;
                data.DataFile  -= data_DataFile;
                data.DataImage -= data_DataImage;
                data.DataSound -= data_DataSound;
            }
        }
Exemplo n.º 9
0
        //
        // Constructor
        //
        internal NikonObject(NikonMd3 md3, NikonObject parent, uint id)
        {
            _md3    = md3;
            _parent = parent;
            _id     = id;

            _object           = new NkMAIDObject();
            _object.refClient = new IntPtr(_uniqueValue);
            _uniqueValue++;

            _completionProc = new MAIDCompletionProcDelegate(CompletionProc);
            _eventProc      = new MAIDEventProcDelegate(EventProc);
            _progressProc   = new MAIDProgressProcDelegate(ProgressProc);
            _dataProc       = new MAIDDataProcDelegate(DataProc);
            _uiRequestProc  = new MAIDUIRequestProcDelegate(UIRequestProc);
        }
Exemplo n.º 10
0
        //
        // Get Children
        //
        internal NikonObject[] GetChildren()
        {
            List <NikonObject> children = new List <NikonObject>();

            NikonEnumWithData e = GetEnumWithData(eNkMAIDCapability.kNkMAIDCapability_Children);

            for (int i = 0; i < e.nativeEnum.ulElements; i++)
            {
                uint childId = BitConverter.ToUInt32(e.buffer, i * 4);

                NikonObject child = new NikonObject(_md3, this, childId);

                children.Add(child);
            }

            return(children.ToArray());
        }
Exemplo n.º 11
0
        unsafe void DataItemGetVideoImage(NikonObject data)
        {
            string     name            = data.GetString(eNkMAIDCapability.kNkMAIDCapability_Name);
            NkMAIDSize videoDimensions = data.GetSize(eNkMAIDCapability.kNkMAIDCapability_Pixels);

            NkMAIDGetVideoImage videoImage = new NkMAIDGetVideoImage();

            data.GetGeneric(eNkMAIDCapability.kNkMAIDCapability_GetVideoImage, new IntPtr(&videoImage));

            // Note: Download 4MB at the time
            const int chunkSize = 4 * 1024 * 1024;

            uint totalSize = videoImage.ulDataSize;

            for (uint offset = 0; offset < totalSize; offset += chunkSize)
            {
                uint fragmentSize = Math.Min(chunkSize, totalSize - offset);

                byte[] buffer = new byte[fragmentSize];

                fixed(byte *pBuffer = buffer)
                {
                    videoImage.ulOffset   = offset;
                    videoImage.ulReadSize = (uint)buffer.Length;
                    videoImage.ulDataSize = (uint)buffer.Length;
                    videoImage.pData      = new IntPtr(pBuffer);

                    data.GetArrayGeneric(eNkMAIDCapability.kNkMAIDCapability_GetVideoImage, new IntPtr(&videoImage));
                }

                NikonVideoFragment fragment = new NikonVideoFragment(
                    name,
                    totalSize,
                    offset,
                    buffer,
                    videoDimensions.w,
                    videoDimensions.h);

                Scheduler.Callback(new VideoFragmentReadyDelegate(OnVideoFragmentReady), this, fragment);
            }
        }
Exemplo n.º 12
0
        internal override void HandleEvent(NikonObject obj, eNkMAIDEvent currentEvent, uint data)
        {
            switch (currentEvent)
            {
                case eNkMAIDEvent.kNkMAIDEvent_AddChild:
                case eNkMAIDEvent.kNkMAIDEvent_AddChildInCard:
                    HandleAddChild(data);
                    break;

                case eNkMAIDEvent.kNkMAIDEvent_AddPreviewImage:
                    HandleAddPreviewImage(data);
                    break;

                case eNkMAIDEvent.kNkMAIDEvent_CaptureComplete:
                    Scheduler.Callback(new CaptureCompleteDelegate(OnCaptureComplete), this, (int)data);
                    break;

                case eNkMAIDEvent.kNkMAIDEvent_CapChange:
                    Scheduler.Callback(new CapabilityChangedDelegate(OnCapabilityChanged), this, (eNkMAIDCapability)data);
                    break;

                case eNkMAIDEvent.kNkMAIDEvent_CapChangeValueOnly:
                    Scheduler.Callback(new CapabilityChangedDelegate(OnCapabilityValueChanged), this, (eNkMAIDCapability)data);
                    break;

                case eNkMAIDEvent.kNkMAIDEvent_RecordingInterrupted:
                    Scheduler.Callback(new VideoRecordingInterruptedDelegate(OnVideoRecordingInterrupted), this, (int)data);
                    break;

                default:
                    Debug.Print("Unhandled event: " + currentEvent + " (" + data.ToString() + ")");
                    break;
            }
        }
Exemplo n.º 13
0
        internal NikonDevice(NikonMd3 md3, NikonScheduler scheduler, NikonObject parent, NikonModuleType moduleType, uint deviceId)
            : base(md3, scheduler)
        {
            Debug.Assert(Scheduler.WorkerThreadId == Thread.CurrentThread.ManagedThreadId);

            ModuleType = moduleType;

            NikonObject source = new NikonObject(md3, parent, deviceId);
            InitializeObject(source);
        }
Exemplo n.º 14
0
        void _object_Event(NikonObject sender, IntPtr refClient, eNkMAIDEvent ulEvent, UInt32 data)
        {
            switch (ulEvent)
            {
                case eNkMAIDEvent.kNkMAIDEvent_CapChange:
                    RefreshCaps();
                    break;
            }

            HandleEvent(sender, ulEvent, data);
        }
Exemplo n.º 15
0
        internal void InitializeObject(NikonObject obj)
        {
            _object = obj;
            _object.Open();
            _object.Event += _object_Event;

            RefreshCaps();
        }
Exemplo n.º 16
0
 internal virtual void HandleEvent(NikonObject obj, eNkMAIDEvent currentEvent, uint data)
 {
     // Note: Overridden in inheritors
 }
Exemplo n.º 17
0
        internal override void HandleEvent(NikonObject obj, eNkMAIDEvent currentEvent, uint data)
        {
            switch (currentEvent)
            {
                case eNkMAIDEvent.kNkMAIDEvent_AddChild:
                    HandleAddChild(data);
                    break;

                case eNkMAIDEvent.kNkMAIDEvent_RemoveChild:
                    HandleRemoveChild(data);
                    break;
            }
        }
Exemplo n.º 18
0
 internal virtual void HandleEvent(NikonObject obj, eNkMAIDEvent currentEvent, IntPtr data)
 {
     // Note: Overridden in inheritors
 }
Exemplo n.º 19
0
 void data_Progress(NikonObject sender,
     eNkMAIDCommand ulCommand,
     UInt32 ulParam,
     IntPtr refComplete,
     UInt32 ulDone,
     UInt32 ulTotal)
 {
     Scheduler.Callback(new ProgressDelegate(OnProgress), this, (eNkMAIDDataObjType)sender.Id, (int)ulDone, (int)ulTotal);
 }
Exemplo n.º 20
0
 void data_DataSound(NikonObject sender, NkMAIDSoundInfo soundInfo, IntPtr data)
 {
     Debug.Print("DataProcSoundInfo event fired");
 }
Exemplo n.º 21
0
 void data_DataImage(NikonObject sender, NkMAIDImageInfo imageInfo, IntPtr data)
 {
     NikonThumbnail thumbnail = new NikonThumbnail(imageInfo, data);
     Scheduler.Callback(new ThumbnailReadyDelegate(OnThumbnailReady), this, thumbnail);
 }
Exemplo n.º 22
0
        //
        // Get Children
        //
        internal NikonObject[] GetChildren()
        {
            List<NikonObject> children = new List<NikonObject>();

            NikonEnumWithData e = GetEnumWithData(eNkMAIDCapability.kNkMAIDCapability_Children);

            for (int i = 0; i < e.nativeEnum.ulElements; i++)
            {
                uint childId = BitConverter.ToUInt32(e.buffer, i * 4);

                NikonObject child = new NikonObject(_md3, this, childId);

                children.Add(child);
            }

            return children.ToArray();
        }
Exemplo n.º 23
0
        void HandleAddChild(IntPtr id)
        {
            NikonObject item = new NikonObject(Md3, Object, (uint)id.ToInt32());

            List <uint> dataIds = new List <uint>();

            item.Open();
            item.Event += (NikonObject obj, IntPtr refClient, eNkMAIDEvent currentEvent, IntPtr data) =>
            {
                if (currentEvent == eNkMAIDEvent.kNkMAIDEvent_AddChild)
                {
                    dataIds.Add((uint)data.ToInt32());
                }
            };

            item.EnumChildren();

            _currentItemId = item.Id;

            foreach (var dataId in dataIds)
            {
                eNkMAIDDataObjType dataObjectType = (eNkMAIDDataObjType)dataId;

                NikonObject data = new NikonObject(Md3, item, dataId);

                data.Open();

                switch (dataObjectType)
                {
                case eNkMAIDDataObjType.kNkMAIDDataObjType_Thumbnail:
                case eNkMAIDDataObjType.kNkMAIDDataObjType_File | eNkMAIDDataObjType.kNkMAIDDataObjType_Thumbnail:
                    // Note:
                    // We do a 'thread-unsafe' check of the thumbnail-ready event here. No
                    // need to acquire if the user hasn't hooked up the thumbnail event.
                    if (_thumbnailReady != null)
                    {
                        DataItemAcquire(data);
                    }
                    break;

                case eNkMAIDDataObjType.kNkMAIDDataObjType_Image:
                case eNkMAIDDataObjType.kNkMAIDDataObjType_Sound:
                case eNkMAIDDataObjType.kNkMAIDDataObjType_File:
                case eNkMAIDDataObjType.kNkMAIDDataObjType_File | eNkMAIDDataObjType.kNkMAIDDataObjType_Image:
                case eNkMAIDDataObjType.kNkMAIDDataObjType_File | eNkMAIDDataObjType.kNkMAIDDataObjType_Sound:
                    DataItemAcquire(data);
                    break;

                case eNkMAIDDataObjType.kNkMAIDDataObjType_Video:
                    // Note:
                    // We do a 'thread-unsafe' check of the videofragment-ready event here. No
                    // need to download videos if the user hasn't hooked up the event.
                    if (_videoFragmentReady != null)
                    {
                        DataItemGetVideoImage(data);
                    }
                    break;

                default:
                    Debug.Print("Unknown data object type: " + dataObjectType.ToString());
                    break;
                }

                data.Close();
            }

            item.Close();
        }
Exemplo n.º 24
0
        void data_DataImage(NikonObject sender, NkMAIDImageInfo imageInfo, IntPtr data)
        {
            NikonThumbnail thumbnail = new NikonThumbnail(imageInfo, data);

            Scheduler.Callback(new ThumbnailReadyDelegate(OnThumbnailReady), this, thumbnail);
        }
Exemplo n.º 25
0
        void DataItemAcquire(NikonObject data)
        {
            // Listen for progress
            data.Progress += data_Progress;

            // Listen for data
            data.DataFile += data_DataFile;
            data.DataImage += data_DataImage;
            data.DataSound += data_DataSound;

            // Try to acquire the data object
            try
            {
                data.CapStart(
                    eNkMAIDCapability.kNkMAIDCapability_Acquire,
                    eNkMAIDDataType.kNkMAIDDataType_Null,
                    0);
            }
            catch (NikonException ex)
            {
                // Is this a 'NotSupported' exception?
                bool isNotSupported = (ex.ErrorCode == eNkMAIDResult.kNkMAIDResult_NotSupported);

                // Is this a 'Thumbnail' data object?
                bool isThumbnail = (data.Id == (uint)eNkMAIDDataObjType.kNkMAIDDataObjType_Thumbnail);

                // According to the documentation, acquiring a thumbnail data object
                // sometimes produces a NotSupported error. Apparently this is expected,
                // so we ignore this specific case here.
                bool isAllowed = isNotSupported && isThumbnail;

                if (isAllowed)
                {
                    Debug.Print("Failed to retrieve thumbnail image");
                }
                else
                {
                    // If this is some other case, rethrow the exception
                    throw;
                }
            }
            finally
            {
                // Unhook data object events
                data.Progress -= data_Progress;
                data.DataFile -= data_DataFile;
                data.DataImage -= data_DataImage;
                data.DataSound -= data_DataSound;
            }
        }
Exemplo n.º 26
0
        void HandleAddChild(uint id)
        {
            NikonObject item = new NikonObject(Md3, Object, id);

            List<uint> dataIds = new List<uint>();

            item.Open();
            item.Event += (NikonObject obj, IntPtr refClient, eNkMAIDEvent currentEvent, uint data) =>
            {
                if (currentEvent == eNkMAIDEvent.kNkMAIDEvent_AddChild)
                {
                    dataIds.Add(data);
                }
            };

            item.EnumChildren();

            _currentItemId = item.Id;

            foreach (uint dataId in dataIds)
            {
                eNkMAIDDataObjType dataObjectType = (eNkMAIDDataObjType)dataId;

                NikonObject data = new NikonObject(Md3, item, dataId);

                data.Open();

                switch (dataObjectType)
                {
                    case eNkMAIDDataObjType.kNkMAIDDataObjType_Thumbnail:
                    case eNkMAIDDataObjType.kNkMAIDDataObjType_File | eNkMAIDDataObjType.kNkMAIDDataObjType_Thumbnail:
                        // Note:
                        // We do a 'thread-unsafe' check of the thumbnail-ready event here. No
                        // need to acquire if the user hasn't hooked up the thumbnail event.
                        if (_thumbnailReady != null)
                        {
                            DataItemAcquire(data);
                        }
                        break;

                    case eNkMAIDDataObjType.kNkMAIDDataObjType_Image:
                    case eNkMAIDDataObjType.kNkMAIDDataObjType_Sound:
                    case eNkMAIDDataObjType.kNkMAIDDataObjType_File:
                    case eNkMAIDDataObjType.kNkMAIDDataObjType_File | eNkMAIDDataObjType.kNkMAIDDataObjType_Image:
                    case eNkMAIDDataObjType.kNkMAIDDataObjType_File | eNkMAIDDataObjType.kNkMAIDDataObjType_Sound:
                        DataItemAcquire(data);
                        break;

                    case eNkMAIDDataObjType.kNkMAIDDataObjType_Video:
                        // Note:
                        // We do a 'thread-unsafe' check of the videofragment-ready event here. No
                        // need to download videos if the user hasn't hooked up the event.
                        if (_videoFragmentReady != null)
                        {
                            DataItemGetVideoImage(data);
                        }
                        break;

                    default:
                        Debug.Print("Unknown data object type: " + dataObjectType.ToString());
                        break;
                }

                data.Close();
            }

            item.Close();
        }
Exemplo n.º 27
0
        unsafe void DataItemGetVideoImage(NikonObject data)
        {
            string name = data.GetString(eNkMAIDCapability.kNkMAIDCapability_Name);
            NkMAIDSize videoDimensions = data.GetSize(eNkMAIDCapability.kNkMAIDCapability_Pixels);

            NkMAIDGetVideoImage videoImage = new NkMAIDGetVideoImage();
            data.GetGeneric(eNkMAIDCapability.kNkMAIDCapability_GetVideoImage, new IntPtr(&videoImage));

            // Note: Download 4MB at the time
            const int chunkSize = 4 * 1024 * 1024;

            uint totalSize = videoImage.ulDataSize;

            for (uint offset = 0; offset < totalSize; offset += chunkSize)
            {
                uint fragmentSize = Math.Min(chunkSize, totalSize - offset);

                byte[] buffer = new byte[fragmentSize];

                fixed (byte* pBuffer = buffer)
                {
                    videoImage.ulOffset = offset;
                    videoImage.ulReadSize = (uint)buffer.Length;
                    videoImage.ulDataSize = (uint)buffer.Length;
                    videoImage.pData = new IntPtr(pBuffer);

                    data.GetArrayGeneric(eNkMAIDCapability.kNkMAIDCapability_GetVideoImage, new IntPtr(&videoImage));
                }

                NikonVideoFragment fragment = new NikonVideoFragment(
                    name,
                    totalSize,
                    offset,
                    buffer,
                    videoDimensions.w,
                    videoDimensions.h);

                Scheduler.Callback(new VideoFragmentReadyDelegate(OnVideoFragmentReady), this, fragment);
            }
        }
Exemplo n.º 28
0
 void data_DataSound(NikonObject sender, NkMAIDSoundInfo soundInfo, IntPtr data)
 {
     Debug.Print("DataProcSoundInfo event fired");
 }
Exemplo n.º 29
0
        void data_DataFile(NikonObject sender, NkMAIDFileInfo fileInfo, IntPtr data)
        {
            if (fileInfo.ulStart == 0)
            {
                Debug.Assert(_currentImage == null);

                int size = (int)fileInfo.ulTotalLength;
                NikonImageType type = (NikonImageType)(_currentItemId >> 27);
                int number = (int)((_currentItemId << 8) >> 8);
                bool isFragmentOfRawPlusJpeg = (_currentItemId & (1 << 26)) != 0;

                _currentImage = new NikonImage(size, type, number, isFragmentOfRawPlusJpeg);
            }

            Debug.Assert(_currentImage != null);

            int offset = (int)fileInfo.ulStart;
            int length = (int)fileInfo.ulLength;

            _currentImage.CopyFrom(data, offset, length);

            bool complete = (fileInfo.ulTotalLength == fileInfo.ulStart + fileInfo.ulLength);

            if (complete)
            {
                NikonImage image = _currentImage;
                _currentImage = null;

                Scheduler.Callback(new ImageReadyDelegate(OnImageReady), this, image);
            }
        }
Exemplo n.º 30
0
        //
        // Constructor
        //
        internal NikonObject(NikonMd3 md3, NikonObject parent, uint id)
        {
            _md3 = md3;
            _parent = parent;
            _id = id;

            _object = new NkMAIDObject();
            _object.refClient = new IntPtr(_uniqueValue);
            _uniqueValue++;

            _completionProc = new MAIDCompletionProcDelegate(CompletionProc);
            _eventProc = new MAIDEventProcDelegate(EventProc);
            _progressProc = new MAIDProgressProcDelegate(ProgressProc);
            _dataProc = new MAIDDataProcDelegate(DataProc);
            _uiRequestProc = new MAIDUIRequestProcDelegate(UIRequestProc);
        }