~ubuntu-branches/ubuntu/saucy/gnash/saucy-proposed

« back to all changes in this revision

Viewing changes to cygnal/libnet/diskstream.cpp

  • Committer: Package Import Robot
  • Author(s): Micah Gersten
  • Date: 2012-03-04 03:19:06 UTC
  • mfrom: (1.1.18) (3.1.24 sid)
  • Revision ID: package-import@ubuntu.com-20120304031906-p6q5rnb0xhgpof7o
Tags: 0.8.10-3ubuntu1
* Merge from Debian testing (FFe: LP: #940876), remaining changes:
  - Use mozilla-flashplugin as the alternative for now
  - Change xulrunner-dev build dep to firefox-dev
* Drop the plugin API porting patch, this has been fixed upstream
  - drop debian/patches*
* Drop the following change as we want Adobe's player to take priority
  if it's installed
  - Set alternative priority to 50 so that it matches Adobe Flash's priority

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
// stream.cpp:  Network streaming server for Cygnal, for Gnash.
2
2
// 
3
 
//   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010,
4
 
//   2011 Free Software Foundation, Inc
 
3
//   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
 
4
//   Free Software Foundation, Inc
5
5
// 
6
6
// This program is free software; you can redistribute it and/or modify
7
7
// it under the terms of the GNU General Public License as published by
23
23
#endif
24
24
 
25
25
#include <sys/types.h>
 
26
#include <boost/cstdint.hpp>
26
27
#include <sys/stat.h>
27
28
#include <fcntl.h>
28
29
#include <iostream>
303
304
DiskStream::~DiskStream()
304
305
{
305
306
    GNASH_REPORT_FUNCTION;
306
 
    log_debug("Deleting %s on fd #%d", _filespec, _filefd);
 
307
    log_debug(_("Deleting %s on fd #%d"), _filespec, _filefd);
307
308
 
308
309
    if (_filefd) {
309
310
        ::close(_filefd);
339
340
        return true;
340
341
    }
341
342
    return false;
342
 
};
 
343
}
343
344
 
344
345
/// \brief Close the open disk file, but stay resident in memory.
345
346
void
347
348
{
348
349
    // GNASH_REPORT_FUNCTION;
349
350
 
350
 
    log_debug("Closing %s on fd #%d", _filespec, _filefd);
 
351
    log_debug(_("Closing %s on fd #%d"), _filespec, _filefd);
351
352
 
352
353
    if (_filefd) {
353
354
        ::close(_filefd);
400
401
{
401
402
    GNASH_REPORT_FUNCTION;
402
403
 
403
 
    log_debug("%s: offset is: %d", __FUNCTION__, offset);
 
404
 
 
405
    log_debug(_("%s: offset is: %d"), __FUNCTION__, offset);
404
406
 
405
407
    // store the offset we came in with so next time we know where to start
406
408
    _offset = offset;
414
416
        if (offset % _pagesize) {
415
417
            // calculate the number of pages
416
418
            page = ((offset - (offset % _pagesize)) / _pagesize) * _pagesize;
417
 
            log_debug("Adjusting offset from %d to %d so it's page aligned.",
 
419
            log_debug(_("Adjusting offset from %d to %d so it's page aligned."),
418
420
                      offset, page);
419
421
        } else {
420
 
            log_debug("Offset is page aligned already");
 
422
            log_debug(_("Offset is page aligned already"));
421
423
        }
422
424
    }
423
425
 
424
426
    // Figure out the maximum number of bytes we can load into memory.
425
427
    size_t loadsize = 0;
426
428
    if (filesize < _max_memload) {
427
 
        log_debug("Loading entire file of %d bytes into memory segment", filesize);
 
429
        log_debug(_("Loading entire file of %d bytes into memory segment"),
 
430
                    filesize);
428
431
        loadsize = filesize;
429
432
    } else {
430
 
        log_debug("Loading partial file of %d bytes into memory segment", filesize, _max_memload);
 
433
        log_debug(_("Loading partial file of %d bytes into memory segment"),
 
434
                  filesize, _max_memload);
431
435
        loadsize = _max_memload;
432
436
    }
433
437
    
435
439
    // this DiskStream, so sufficient memory will already be allocated for this data.
436
440
    // If the data came from a disk based file, then we allocate enough memory to hold it.
437
441
    if (_dataptr) {
438
 
        log_debug("Using existing Buffer for file");
 
442
        log_debug(_("Using existing Buffer for file"));
439
443
        return _dataptr + offset;
440
444
    }
441
445
    
486
490
                                                     _filefd, page));
487
491
#endif
488
492
    } else {
489
 
        log_error (_("Couldn't load file %s"), _filespec);
 
493
        log_error(_("Couldn't load file %s"), _filespec);
490
494
        return 0;
491
495
    }
492
496
    
493
497
    if (dataptr == MAP_FAILED) {
494
 
        log_error (_("Couldn't map file %s into memory: %s"),
 
498
        log_error(_("Couldn't map file %s into memory: %s"),
495
499
                   _filespec, strerror(errno));
496
500
        return 0;
497
501
    } else {
498
 
        log_debug (_("File %s a offset %d mapped to: %p"), _filespec, offset, (void *)dataptr);
 
502
        log_debug(_("File %s a offset %d mapped to: %p"), _filespec, offset, (void *)dataptr);
499
503
        clock_gettime (CLOCK_REALTIME, &_last_access);
500
504
        _dataptr = dataptr;
501
505
        // map the seekptr to the end of data
579
583
    if (fd < 0) {
580
584
        log_error(strerror(errno));
581
585
    }
582
 
    log_debug("Writing data (%d bytes) to disk: \"%s\"", size, filespec);
 
586
    log_debug(_("Writing data (%d bytes) to disk: \"%s\""), size, filespec);
583
587
    ::write(fd, data, size);
584
588
    ::close(fd);
585
589
 
653
657
    _statistics = statistics;
654
658
    _filespec = filespec;
655
659
 
656
 
    log_debug("Trying to open %s", filespec);
 
660
    log_debug(_("Trying to open %s"), filespec);
657
661
    
658
662
    if (getFileStats(filespec)) {
659
663
        boost::mutex::scoped_lock lock(io_mutex);
660
664
        _filefd = ::open(_filespec.c_str(), O_RDONLY);
661
665
        log_debug (_("Opening file %s (fd #%d), %lld bytes in size."),
662
666
                   _filespec, _filefd,
663
 
                 (long long int) _filesize);
 
667
                   (boost::int64_t) _filesize);
664
668
        _state = OPEN;
665
669
        _filetype = determineFileType(filespec);
666
670
        loadToMem(0); // load the first page into memory
720
724
        }
721
725
        switch (_state) {
722
726
          case NO_STATE:
723
 
              log_network("No Diskstream open %s for net fd #%d", _filespec, netfd);
 
727
              log_network(_("No Diskstream open %s for net fd #%d"),
 
728
                          _filespec, netfd);
724
729
              break;
725
730
          case CREATED:
726
731
          case CLOSED:
727
732
              if (_dataptr) {
728
 
                  log_network("Diskstream %s is closed on net fd #%d.", _filespec, netfd);
 
733
                  log_network(_("Diskstream %s is closed on net fd #%d."),
 
734
                              _filespec, netfd);
729
735
              }
730
736
              done = true;
731
737
              continue;
744
750
#else
745
751
                  ret = net.writeNet(netfd, (_dataptr + _offset), (_filesize - _offset));
746
752
                  if (ret != (_filesize - _offset)) {
747
 
                      log_error("In %s(%d): couldn't write %d bytes to net fd #%d! %s",
 
753
                      log_error(_("In %s(%d): couldn't write %d bytes to net fd #%d! %s"),
748
754
                                __FUNCTION__, __LINE__, (_filesize - _offset),
749
755
                                netfd, strerror(errno));
750
756
                  }
751
757
#endif
752
 
                  log_network("Done playing file %s, size was: %d", _filespec, _filesize);
 
758
                  log_network(_("Done playing file %s, size was: %d"),
 
759
                              _filespec, _filesize);
753
760
                  close();
754
761
                  done = true;
755
762
                  // reset to the beginning of the file
761
768
#else
762
769
                  ret = net.writeNet(netfd, (_dataptr + _offset), _pagesize);
763
770
                  if (ret != _pagesize) {
764
 
                      log_error("In %s(%d): couldn't write %d of bytes of data to net fd #%d! Got %d, %s",
 
771
                      log_error(_("In %s(%d): couldn't write %d of bytes of data to net fd #%d! Got %d, %s"),
765
772
                                __FUNCTION__, __LINE__, _pagesize, netfd,
766
773
                                ret, strerror(errno));
767
774
                      return false;
773
780
                case EINVAL:
774
781
                case ENOSYS:
775
782
                case EFAULT:
776
 
                    log_network("ERROR: %s", strerror(errno));
 
783
                    log_error("%s", strerror(errno));
777
784
                    break;
778
785
                default:
779
786
                    break;
793
800
          case MULTICAST:
794
801
              break;
795
802
          case DONE:
796
 
              log_debug("Restarting Disk Stream from the beginning");
 
803
              log_debug(_("Restarting Disk Stream from the beginning"));
797
804
              _offset = 0;
798
805
              _filefd = 0;
799
806
              _state = PLAY;
838
845
//    GNASH_REPORT_FUNCTION;
839
846
 
840
847
    _state = PREVIEW;
841
 
    log_unimpl("%s", __PRETTY_FUNCTION__);
 
848
    log_unimpl(__PRETTY_FUNCTION__);
842
849
    return true; // Default to true    
843
850
}
844
851
 
859
866
//    GNASH_REPORT_FUNCTION;
860
867
    
861
868
    _state = THUMBNAIL;
862
 
    log_unimpl("%s", __PRETTY_FUNCTION__);
 
869
    log_unimpl(__PRETTY_FUNCTION__);
863
870
    return true; // Default to true
864
871
}
865
872
 
872
879
//    GNASH_REPORT_FUNCTION;
873
880
    
874
881
    _state = PAUSE;
875
 
    log_unimpl("%s", __PRETTY_FUNCTION__);
 
882
    log_unimpl(__PRETTY_FUNCTION__);
876
883
    return true; // Default to true
877
884
}
878
885
 
906
913
//    GNASH_REPORT_FUNCTION;
907
914
    
908
915
    _state = UPLOAD;
909
 
    log_unimpl("%s", __PRETTY_FUNCTION__);
 
916
    log_unimpl( __PRETTY_FUNCTION__);
910
917
    return true; // Default to true
911
918
}
912
919
 
917
924
//    GNASH_REPORT_FUNCTION;
918
925
    
919
926
    _state = MULTICAST;
920
 
    log_unimpl("%s", __PRETTY_FUNCTION__);
 
927
    log_unimpl(__PRETTY_FUNCTION__);
921
928
    return true; // Default to true    
922
929
}
923
930
 
946
953
        // does, which is to load the index.html file in that
947
954
        // directry if it exists.
948
955
        if (S_ISDIR(st.st_mode)) {
949
 
          log_debug("%s is a directory, appending index.html\n",
 
956
            log_debug(_("%s is a directory, appending index.html"),
950
957
                    actual_filespec.c_str());
951
958
          if (actual_filespec[actual_filespec.size()-1] != '/') {
952
959
            actual_filespec += '/';
1171
1178
 
1172
1179
// local Variables:
1173
1180
// mode: C++
1174
 
// indent-tabs-mode: t
 
1181
// indent-tabs-mode: nil
1175
1182
// End: